File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes packing classpath errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "packing classpath errors" Watch "packing classpath errors" New topic

packing classpath errors

scott matzka

Joined: Jan 31, 2006
Posts: 9
I have checked out a lot of different posts on this subject. I just don't get it.

Both of these classes are saved in the directory C:/J24work/com/testing and they both compile fine with



C:\J24work>javac com\testing\
C:\J24work>javac com\testing\

this class is saved in directory C:\J24work. When I try and compile with: (classpath= .; C:\J24work)


I get compile errors like bad class file: /, but it's okay it i change the import statement to:

import com.testing.*; ---> import com.testing.Test2;

I would like to know why this is, also what if I had to include a bunch of things from the package, I wouldn't want to import everything separately. I have seen some posts about the classpath looking for class definitions but instead it finds first and uses that, but I'm thoroughly confused. Any help.

[Edit]Move code tags. CR[/edit]
scott matzka

Joined: Jan 31, 2006
Posts: 9
I have moved all the files to C:\J24work and used this compile code:

C:\J24work>javac -d "C:\J24work"
C:\J24work>javac -d "C:\J24work"

which sends only the Test.class and Test2.class files to C:\J24work\com\testing, but still no dice on the compile of using the original import statement, which is import com.testing.*;
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46348
You have a file and a nested directory called com/testing in the same higher directory.
You have and in com/testing and in the higher-level directory. That is what I did, copying your files. And I got this, once I corrected my own errors!
[Campbell@localhost ~]$ cd java
[Campbell@localhost java]$ mkdir com
[Campbell@localhost java]$ cd com
[Campbell@localhost com]$ mkdir testing
[Campbell@localhost com]$ cd ..
[Campbell@localhost java]$ gedit com/testing/
[Campbell@localhost java]$ javac com/testing/ com/testing/
[Campbell@localhost java]$ javac
[Campbell@localhost java]$ java TestingEvent
[Campbell@localhost java]$
If you have all the files in the same directory it would be different, but you have two choices if the directories are already set up.
  • Navigate to lower directories and compile with javac
  • Stay in higher directory and compile with javac com/package/MyFile
  • I did the latter. Note you can compile several files in one instruction. If you compile them separately, TestingEvent has a dependency on Test2 and Test2 has a dependency on Test, so Test2 cannot be compiled before Test and TestingEvent cannot be compiled before Test2.
    Although I am using Linux, you can do the same on Windows, but might have to use \ instead of /.

    Did you find this thread when you searched, and its included links? Or this one (that might be one of the links mentioned earlier)? You should find more information there.

    It ought not to be necessary to set up a classpath variable for this simple application.

    Using javac -d . will work if you have all the files in one folder; the com and testing folders will be set up by the -d command. The . means start in current directory; I don't know whether that instruction works without the .
    scott matzka

    Joined: Jan 31, 2006
    Posts: 9
    Thanks for the info. I got it "magically" working a little bit ago. I don't think I changed anything. I compiled from the src directory without issues and ran with issues. Thanks again though.
    I agree. Here's the link:
    subject: packing classpath errors
    It's not a secret anymore!