How do I get the Java classpath?

The RuntimeMXBean.getClassPath() returns the Java class path that is used by the system class loader to search for class files. This method is equivalent to System.getProperty("java.class.path").

Multiple paths in the Java class path are separated by the path separator character of the platform of the Java virtual machine being monitored.

package org.kodejava.example.lang.management;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;

public class GetClassPath {
    public static void main(String[] args) {
        RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
        String classPath = bean.getClassPath();
        System.out.println("classPath = " + classPath);
    }
}
Wayan Saryada

Wayan Saryada

A programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, JPA, etc. If you need help on Java programming you can hire me on Fiverr.
Wayan Saryada

Leave a Reply