OCA7
ankita modi. wrote:Hi
I read that java command looks classpath for required classes.Now suppose i don't set classpath at environment variable neither through -classpath option although i put jar file of my class in jre/lib/ext folder.Will it run successfully from anywhere without mentioning classpath ?
Thanks.
R. Jain wrote:
ankita modi. wrote:Hi
I read that java command looks classpath for required classes.Now suppose i don't set classpath at environment variable neither through -classpath option although i put jar file of my class in jre/lib/ext folder.Will it run successfully from anywhere without mentioning classpath ?
Thanks.
Here's a line regarding compiler from Javac Doc: -
-cp path or -classpath path
Specify where to find user class files, and (optionally) annotation processors and source files. This classpath overrides the user class path in the CLASSPATH environment variable. If neither CLASSPATH, -cp nor -classpath is specified, the user class path consists of the current directory.
OCA7
The bits of that which I can actually understand look like poor advice.ankita modi. wrote: . . . Your link is dead badly.I believe that as i put jar in jre/lib/ext folder so no need to mention classpath at -cp or environment variable, as javac and java command first search classes at jre/lib/rt.jar then jre/lib/ext folder then at environment variable classpath if any and then finally -cp classpath if any and yes -cp does overwrite environment variable classpath.
gurpeet singh wrote:my memory is poor so please check but i think java extension mechanism( i.e. putting files in jre/lib/ext so that java/javac automatically loads class files from there) work ONLY FOR CLASS FILES AND NOT FOR JAR FILES.
if you place .class file there it will pick but not jar file. again i maybe wrong so please make a sample program and see for yourself.
And Campbell is right. it is not a good idea to set classpath like this. the best way is to by specifying classpath using -cp switch. putting class files there in jre/lib/ext folder can cause conflicts if you have 2 version of classfiles in your classpathh
OCA7
ankita modi. wrote:
gurpeet singh wrote:my memory is poor so please check but i think java extension mechanism( i.e. putting files in jre/lib/ext so that java/javac automatically loads class files from there) work ONLY FOR CLASS FILES AND NOT FOR JAR FILES.
if you place .class file there it will pick but not jar file. again i maybe wrong so please make a sample program and see for yourself.
And Campbell is right. it is not a good idea to set classpath like this. the best way is to by specifying classpath using -cp switch. putting class files there in jre/lib/ext folder can cause conflicts if you have 2 version of classfiles in your classpathh
Jar files will surely work there,
OCPJP 6 86%
Nikhil Sagar wrote:then what is the real use of jre/lib/ext folder ??
Jeff Verdegan wrote:
Nikhil Sagar wrote:then what is the real use of jre/lib/ext folder ??
There are a few speical jar files that have to go there to work correctly. The only case I recall off the top of my head is certain security/encryption stuff, though that may have been back before the encryption classes were part of the core API. It's for stuff that's supposed to get loaded by the "null" or "default" classloader, and I believe the JVM treats it with a higher level of trust than classes loaded with other classloaders. Putting something there that doesn't belong there is a security risk. Plus it just leads to a mess if you have more than a couple of apps that you're running. Better to give each app its own directory tree of jar files and resources.
OCPJP 6 86%
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|