• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Packages are not detecting

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have created one program, in that im importing some classes from the user defined packages and those packages are in the same directory where my program is but while compiling its throwing compiler error saying "package does not exist". Can u plz tell me why its not detecting the packages.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try looking at how you CLASSPATH is set up. This is more than likely the problem. Remember that packages correspond to a directory structure, so make sure that your directory structure is correct.
[ April 06, 2005: Message edited by: Joel McNary ]
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey joel,

does it mean, that at the time of compiling (if I haven't compiled a certain file in the package I am about to use, I should first compile tht file) and then compile my code that imports that package/class.

Also, when you mentioned classpath with regards to this problem, I want to ask you if:

1. At the command prompt, I get into that directory (package) and then compile tht particular file OR
2. just compile from the same directory using something like ../Food/Fruits.java

I am not sure if the two make any difference at all....

the question may sound silly, but once I had this problem (it did not recognize the package when I tried compiling), however I am not sure what I did but after that it worked
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kiennjal shah:

does it mean, that at the time of compiling (if I haven't compiled a certain file in the package I am about to use, I should first compile tht file) and then compile my code that imports that package/class.



javac will compile source file dependencies if the source can be located in the classpath (see the javac documentation for the details on how this works)

Originally posted by kiennjal shah:

Also, when you mentioned classpath with regards to this problem, I want to ask you if:

1. At the command prompt, I get into that directory (package) and then compile tht particular file OR
2. just compile from the same directory using something like ../Food/Fruits.java

I am not sure if the two make any difference at all....



It will not make a difference. I prefer to keep my source and class files seperate (makes creating JAR's and clearing out old classes easier), so I make a root project directory with src and classes directories. Compile from the project root with

and it will put Fruits.class in classes/Food.
As your projects get bigger, compiling and packaging by hand will become tedious and you'll want to look at automating the process with something like Ant.
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic