Suppose there is a jar file named callme.jar
and it's located in several directories,
how to analyse which one of them is used at run-time?
Suppose there is a jar file named callme.jar
and it's located in several directories,
how to analyse which one of them is used at run-time?
Might not be the easiest method, but you could look at what files the process has open and determine it from that.
If you're on windows you could use Process Explorer to see what files the process has open at any given time, or Process Monitor to watch the filesystem access as it runs. There will be a lot of noise, but you could figure it out from there.
If you're on the Mac I think the built-in Activity Monitor can give you a list of open files. Sadly I don't know the command you'd use in Linux.
Invoke the java
executable with the -verbose:class
argument. This will produce output like:
[Loaded org.apache.log4j.helpers.ThreadLocalMap from file:/C:/.../1.2.14/log4j-1.2.14.jar]
[Loaded org.apache.commons.cli.Option from file:/C:/.../commons-cli-1.2.jar]
Try this piece of code :
//Get the System Classloader
ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();
//Get the URLs
URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();
System.out.println("CURRENT CLASSPATH :");
for(int i=0; i< urls.length; i++){
System.out.println(urls[i].getFile());
}
System.out.println("END OF CLASSPATH");