Dave Tolls wrote:Show us the full command you are using to compile them, including the directory you are in.
Also, are those classes in a com/bar and com/foo folder?
Apart from the fact that my Linux box has slightly different names for the folders you should find the same instructions should work on Windows®.mkdir com
campbell@campbellsComputer:~/java$ cd com
campbell@campbellsComputer:~/java/com$ mkdir foo
campbell@campbellsComputer:~/java/com$ mkdir bar
campbell@campbellsComputer:~/java/com$ gedit bar/Y.java
campbell@campbellsComputer:~/java/com$ gedit foo/X.java
campbell@campbellsComputer:~/java/com$ cd ..
campbell@campbellsComputer:~/java$ javac com/foo/X.java
campbell@campbellsComputer:~/java$ gedit com/foo/X.java
campbell@campbellsComputer:~/java$ javac com/foo/X.java
campbell@campbellsComputer:~/java$ javac com/bar/Y.java
campbell@campbellsComputer:~/java$ java com.bar.Y
applied
Campbell Ritchie wrote:You should compile X first because it is a dependency for Y.
I tried it with your code, only I commented back in the apply call and changed the int to final int:-Apart from the fact that my Linux box has slightly different names for the folders you should find the same instructions should work on Windows®.mkdir com
campbell@campbellsComputer:~/java$ cd com
campbell@campbellsComputer:~/java/com$ mkdir foo
campbell@campbellsComputer:~/java/com$ mkdir bar
campbell@campbellsComputer:~/java/com$ gedit bar/Y.java
campbell@campbellsComputer:~/java/com$ gedit foo/X.java
campbell@campbellsComputer:~/java/com$ cd ..
campbell@campbellsComputer:~/java$ javac com/foo/X.java
campbell@campbellsComputer:~/java$ gedit com/foo/X.java
campbell@campbellsComputer:~/java$ javac com/foo/X.java
campbell@campbellsComputer:~/java$ javac com/bar/Y.java
campbell@campbellsComputer:~/java$ java com.bar.Y
applied
Dave Tolls wrote:You need to give it the classpath.
The easiest (IMO) is to simply compile from the E:\Java Programs directory (ie the source directory).
javac -cp . com\bar\Y.java
In fact, you won't need the "-cp ." as that is the default classpath, but if you have defined an global environment variable CLASSPATH (which you should not do) then you will need to include "-cp ." ...
Does that make sense?
ETA: And how long did it take me to finish writing that?
Blimey...
DT did give you the answer before I did.samarth mishra wrote: . . .
Thanks Dave!
You actually have to be at a level where you can write com\foo\X.*** and find the file you want. If the package name is com.foo then you have to be able to find that class in the folder com\foo. The -cp option means classpath. The classpath variable tells the compiler and the JVM where to find other dependencies. Don't set a system classpath.. . . I have to be a level above it. . . .
Don't get me started about those stupid light bulbs. |