The Artima Developer Community
Sponsored Link

Java Answers Forum
finding classpath visible to classloader

4 replies on 1 page. Most recent reply: Apr 19, 2002 11:17 PM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Anand

Posts: 5
Nickname: anand
Registered: Mar, 2002

finding classpath visible to classloader Posted: Apr 19, 2002 1:43 PM
Reply to this message Reply
Advertisement
Hi,
Is it possible to findout classpath visible to a classloader for a particuler class at runtime.
Thanks
Anand


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: finding classpath visible to classloader Posted: Apr 19, 2002 2:05 PM
Reply to this message Reply
Try getResource () method of Class class. something like this:

URL url = this.getClass().getResource ( "MyClass.class" ) ;

getResource () uses CLASSPATH to find the class file and this is how you can get the classpath being used for MyClass. However, implementation of JVM is free to choose any criteria other than classpath to find the resourse.

Thanks
Kishori

Anand

Posts: 5
Nickname: anand
Registered: Mar, 2002

Re: finding classpath visible to classloader Posted: Apr 19, 2002 2:24 PM
Reply to this message Reply
will it give all the classpaths or class path for that class. If no then please let me know how to find all the class paths.
Thanks a lot
Anand

Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: finding classpath visible to classloader Posted: Apr 19, 2002 3:42 PM
Reply to this message Reply
Like Kishori said, getResource() gives the location (in other words classpath) to the resource passed as parameter.

Normally, (the keyword being normally) JVMs load classes in a platform-dependent manner. Most use the environment variable of the underlying platform: CLASSPATH. This maps to the system property java.class.path. So, to get the classpath used by a ClassLoader use that system property.

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: finding classpath visible to classloader Posted: Apr 19, 2002 11:17 PM
Reply to this message Reply
To get the CLASSPATH :

String clspath = System.getProperty ( "java.class.path" ) ;

Now you clspath contains the CLASSPATH environmrnt variable value.

Flat View: This topic has 4 replies on 1 page
Topic: ejb and jars Previous Topic   Next Topic Topic: toString() Proper use Please help!!!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use