Know the Current Project/Module Classpath using Java Code

If you want to know what the current classpath is for your code (project/module) then you can make use of the System.getProperty() method with a string argument java.class.path

public class Main {
    
    public static void main(String[] args) {

        String classpath = System.getProperty("java.class.path");
        System.out.println("Current Classpath: " + classpath);

    }
}
Output:

Current Classpath: /Users/dev/Downloads/code/out/production/design-patterns


System.getProperty("java.class.path") method retrieves the value of the classpath property, which contains all the paths where the JVM looks for classes and resources.

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!