Skip to content

How to print current JVM classpath without writing any code

1. The purpose of this post

This post demonstrates how to print the current JVM classpath without writing any code.

2. Environments

  • Java 1.6+

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

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

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

Example.java
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. It is designed for troubleshooting production issues in Java applications without modifying code or restarting servers.

3.2.1 Download and install Arthas

Download
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 entering this command:

Terminal window
exit

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 entering:

Terminal window
java -jar arthas-boot.jar

Choose the PID of your Java process and then enter this command:

Terminal window
jvm

You will get this result: arthas-classpath

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

Summary

This post demonstrated two methods to print the current JVM classpath without writing any code. The traditional method involves using System.getProperty(), while the modern approach leverages the Arthas diagnostic tool. Arthas is particularly useful for production environments, as it allows you to troubleshoot issues without restarting the application. By following the steps outlined in this post, you can easily retrieve the classpath information for your Java applications.

Final Words + More Resources

My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!