This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help!!! I know packages cant be this difficult. :-(

 
C. Magmanum
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to understand packages but its getting a bit difficult.



...compiles fine



Why is my second class giving me this compile error?
package com.example.test does not exist
[ February 23, 2005: Message edited by: Crusty Magmanum ]
 
Joe Ess
Bartender
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crusty, can you change your displayed name to conform to the JavaRanch
naming policy. In short, your name must be a first name and last name, separated by a space and not obviously fake. You can do that here.
Now, about packages. Unless you tell the compiler differently, it will write the class file it generates into the current working directory. Packages work like the file system, so if you have a package named com.example.test, the compiler will expect to find classes in that package in a directory named com/example/test under the current one (or in the classpath, but that's another story). To have the compiler do this automatically, compiler with the -d flag and specify a directory ("." for the current directory is fine). Consult the Java Tutorial chapter on Packages for more info.
[ February 23, 2005: Message edited by: Joe Ess ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might also refer to the chapter on packages in Bruce Eckel's Thinking in Java...
http://www.faqs.org/docs/think_java/TIJ307.htm
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that the issue is with your directory structure in the file system. Packages correspond to directory names, so for the example you gave, you should have the following structure:

You can compile all of your classes from C:\java:

If MyClass.java is not compiled or has been modified, javac should detect this and compile it before it compiles MyClass2.java.

If this doesn't help fix your problem, please describe the directory structure you are using. Hopefully it will help us think of other things you can try.

Keep Coding!

Layne
[ February 23, 2005: Message edited by: Layne Lund ]
 
C. Magmanum
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much for ur suggestions but I'm still not getting anything positive. This is my commandline input

c:\>javac -classpath /somefile/foo.jar -d classes MyClass2.java

The structure is how u suggested but I am not sure how -classpath (in the commmand-line) affects the import in MyClass.java



...my mum calls me crusty
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic