Quazi Irfan wrote:- > Only then my default class path will be (.) and java would automatically include A.jar and B.jar(the other way is to add the jar files using -cp argument, which I want to avoid in this scenario)
All things are lawful, but not all things are profitable.
Paul Clapham wrote:The Java compiler will never automatically include any jar files in your classpath. If you want the compiler to be able to access files in a jar, then you have to put that jar into your classpath. Usually you'd use the -cp argument... I don't see why you would want to avoid that.
Liutauras Vilda wrote:This doc should help you understand some options > http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#options
Campbell Ritchie wrote:Or this Tutorial might help.
...but why I don't have to use the name of the jar file MyJar?
All things are lawful, but not all things are profitable.
Quazi Irfan wrote:
Paul Clapham wrote:The Java compiler will never automatically include any jar files in your classpath. If you want the compiler to be able to access files in a jar, then you have to put that jar into your classpath. Usually you'd use the -cp argument... I don't see why you would want to avoid that.
Yes, but the default class path is (.), and if the jar files are on the default classpath, then those would get automatically include into my program...right?
The Java compiler will never automatically include any jar files in your classpath.
Quazi Irfan wrote:I guess the source of my confusion is how I can access contents of jar file without referencing the jar file itself.
Knute Snortum wrote:It's what's in the Jar file that's important, not the name of the Jar file. Why? Because that's the way it was setup. Did you know that java.util is in a jar file called rt.jar? No? Well, that's because you don't have to. Isn't that nice?
Dave Tolls wrote:The jar file names have nothing to do with import statements or namespaces.
Dave Tolls wrote:...whichever jar file is encountered first when compiling or running will be the one used.
This can happen with large projects accidentally importing different versions of another project...