Jul 1, 2009

Analyse the classpath of a running Java program

Sometimes we come across scenarios where it is required to analyze the classpath of a running java program to make sure that the correct libraries are picked up. In my scenario, I wanted to check whether an endorsed jar has been picked instead of the jar that comes with the JDK. Few of the possible ways of doing this is,

  • Use the '-verbose:class' argument with the 'java' command when starting the program.

  • Use 'System.getProperty("java.class.path");' inside the program to print the classpath.

But both these issues have constraints, thus have a limited usability when it comes to third party application. But the following solution will be more elegant and it can be used while running the java application which might have been developed by us or some other party.

- First locate the process ID of the Java application. If you are on Linux this can be easily done using the system monitor or you can select the hard way, the terminal ;-)

- Once you have identified PID, execute the command, 'lsof -p <PID>' (If you have a large number of dependent libraries, you can take the output of this command into a file by executing 'lsof -p <PID> > <path/to/file>' )

- This will generate the list of open files of that process. This contains the list of JARs, the program keeps in its classpath.




lsof and Unclosed file handlers « 0 and 1’s said...

[...] Posted in Uncategorized by Rama Krishna on August 26, 2009 After checking out a blog entry about analyzing Classpath of a running Java program by Thilina Mahesh Buddhika, i decided to try the command on the Java web server used at my [...]

christi parks said...

Hello, sir i would like to ask that what is the scope of java training, what all topics should be covered and it is kinda bothering me … and has anyone studies from this course http://www.wiziq.com/course/1779-core-and-advance-java-concepts of core and advance java online ?? or tell me any other guidance...
would really appreciate help… and Also i would like to thank for all the information you are providing on java concepts.

Post a Comment