I am using some third party code which when given a '-classpath' command line argument doesnt set the java.class.path, but instead just creates a classloader, adds all the urls for the items on the command line specified classpath to the classloader, and then sets it to be the context classloader. In a plugin class to this code that I have written, I get an instance of this classloader, and somehow need to use it to get back the underlying classpath, so that I can use it in an invocation of JavaCompiler.getTask(...) and compile some other code on the fly. However there doesn't seem to be anyway to get the ClassPath from the ClassLoader, and as java.class.path is unset, I can't seem to access the underlying classpath that the application was initially invoked with...Any ideas?
In short, to get the classpath using System class you should: Use the getProperty(String key) , for the java. class. path key.
How can I get list of all available classes in CLASSPATH at runtime? In Eclipse IDE, you can do this by pressing Ctrl + Shift + T .
If the classloader uses URLs, it must be a URLClassloader
. What you have access to is the URLs which defines the classpath for it along side with its parent ClassLoader
.
To get the URLs, simply do the following:
((URLClassLoader) (Thread.currentThread().getContextClassLoader())).getURLs()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With