Reputation: 2283
my program is in C:\Users\Programs\x.java
X.java is using some files that are in y.jar, z.jar.
y.jar and z.jar are in C:\Users\Programs folder.
(1) C:Users\Programs> javac x.java
(2) C:Users\Programs> javac -classpath y.jar:z.jar x.java
I am not getting any errors when I do (2) but when I do (1) I am getting errors. Isn't that classpath is set to current folder. If so why is it not seeing y.jar and z.jar.
Upvotes: 0
Views: 519
Reputation: 161
Yes, classpath should indeed be set to the current folder by default. However, setting it to a given folder is not the same as setting it to a specific JAR file.
Upvotes: 0
Reputation: 887245
The classpath includes the current folder.
However, it does not include subfolders of the current folder.
If you try to use com.example.MyClass
, Java will look for a file named com/example/MyClass.class
directly inside of each folder in the classpath.
It does not look in subfolders or JARs inside of folders in the classpath.
Upvotes: 1
Reputation: 7452
Contents of a jar residing on the classpath are not automatically added to the classpath itself. A proper classpath in your case would be what you specified in case (2).
Upvotes: 2