System.getProperty("java.class.path")
returns the classpath of my program. However getClassLoader().getURLs()
is also providing me with the classpath (see my other post: how to use getClassLoader)
What is the difference between the two mentioned ways?
Main difference can be found in what they return:
getClassLoader.getURLs()
Returns the search path of URLs for loading classes and resources. This includes the original list of URLs specified to the constructor, along with any URLs subsequently appended by the addURL() method, see link
System.getProperty("java.class.path")
Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the path.separator property, see link
Looking at definition, here are the differences:
More or less it depends on what you are trying to achieve when you have to decide which one to pick.
Cheers !!
One difference is that there is no such method as 'ClassLoader.getURL()'.
The ClassLoader
you get the URLs from (although not by the method you mention, which is non-existent), may not have been the system class loader. It may have been for example a URLClassLoader,
which has nothing to do with the classpath.
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