• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

classpath

 
Ranch Hand
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 375
1
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



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.
 
Marshal
Posts: 79648
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

The bits of that which I can actually understand look like poor advice.
Don’t put any of your work into the Java installation folders.
Use the -cp option, unless you can arrange everything to be in the same directory structure.
No -cp does not overwrite anything, but overrides the system classpath.
It is a bad idea to set a system classpath at all, even though older books tell you how to do it.
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Marshal
Posts: 79648
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Worse things can happen than conflict of types if you put your own .class files in the Java installation folder. What happens when you uninstall it and install a new version of Java?
 
Campbell Ritchie
Marshal
Posts: 79648
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I think, but I am not certain, that the javac tool and the JVM will use the first file found which matches the name required and then stop looking. You would not then get a type conflict, but you might select a file different from what you expect, leading to errors difficult to diagnose.
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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, i don't understand any reason to not work.And there will be no conflict, if required class is found at first classpath then compiler wont look next classpath if any.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to this link, yes jar files placed at ext folder is added in the classpath. Check the example "Running AreaApp by Using the Extension Mechanism" in the link.
 
Campbell Ritchie
Marshal
Posts: 79648
380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stilll don’t like it. All is well until you reinstall Java and the folder is deleted!
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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,



It doesn't matter if it works. It's the wrong place to put your jar files. That's not what that directory is for.
 
Ranch Hand
Posts: 216
Tomcat Server Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
then what is the real use of jre/lib/ext folder ??
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Nikhil Sagar
Ranch Hand
Posts: 216
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



 
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
reply
    Bookmark Topic Watch Topic
  • New Topic