• Post Reply Bookmark Topic Watch Topic
  • New Topic

Packages are not detecting  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!