1. The purpose of this post

I would demo how to print current JVM classpath without write any code.

2. Environments

  • java 1.6+

3. How to print current JVM classpath without write any code

3.1 The old way: Use System.getProperty() to get it

The old way to print the JVM current classpath at runtime is write the following code:

System.out.println(System.getProperties().get("java.class.path"));

3.2 The new way: use arthas

arthas is a free java diagnostic tool provided by alibaba, and it’s dedicated for troubleshooting production issues for Java applications without modifying code or restarting servers.

3.2.1 Download and install arthas

wget https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar

You would get this: arthas

3.2.2 Start your application and find the PID of it

Now exit arthas by input this command:

exit

Now start your java application and reference this article to find and determine the PID of your java application.

3.2.3 Use arthas to show your classpath at runtime

Start arthas by input:

java -jar arthas-boot.jar

choose the PID of your java process and then input this command:

jvm

Then you would get this result: arthas-classpath

You can see that you can print the classpath without writing any code or restarting your application.