This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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 Test2.java first and uses that, but I'm thoroughly confused. Any help.
[Edit]Move code tags. CR[/edit]
Joined: Jan 31, 2006
I have moved all the files to C:\J24work and used this compile code:
which sends only the Test.class and Test2.class files to C:\J24work\com\testing, but still no dice on the compile of TestingEvent.java using the original import statement, which is import com.testing.*;
You have a file TestingEvent.java and a nested directory called com/testing in the same higher directory.
You have Test.java and Test2.java in com/testing and TestingEvent.java 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/Test.java&
[Campbell@localhost java]$ javac com/testing/Test.java com/testing/Test2.java
[Campbell@localhost java]$ javac TestingEvent.java
[Campbell@localhost java]$ java TestingEvent
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 MyFile.java
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 . Test.java 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 .
Joined: Jan 31, 2006
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.