Program to demonstrate how to get Java classpath using RuntimeMXBean and System class in Java
Output of the program :
package com.hubberspot.example;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
public class JavaClassPath {
public static void main(String[] args) {
// Create RuntimeMXBean object through getRuntimeMXBean()
// of the ManagementFactory
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
// Call getClassPath() of RuntimeMXBean object to get
// java class path
String classpath = runtime.getClassPath();
System.out.println("Java Class Path : " + classpath);
// Call getProperty("java.class.path") of System class
// to get another way of getting java class path
classpath = System.getProperty("java.class.path");
System.out.println("Java Class Path : " + classpath);
}
}
Output of the program :
