How To Get Classpath in Java

This example demonstrates how to get the classpath string using the Java program. It is simple that you just need to use the System.getProperty() method with the classpath variable name which will return the classpath string. Lets look at the example.

package javabeat.net.core;
/**
 * This example program prints the classpath value
 *
 * @author krishna
 *
 */
public class JavaCoreExample {
	public static void main(String[] args) {
		// Call System property to get the classpath value
		String classpathStr = System.getProperty("java.class.path");
		System.out.print(classpathStr);
	}
}

Output

/home/krishna/workspace/Java Project/bin:/home/krishna/JARS/itext-5.4.4/itextpdf-5.4.4.jar:/home/krishna/JARS/itext-5.4.4/itext-pdfa-5.4.4.jar:/home/krishna/JARS/itext-5.4.4/itext-xtra-5.4.4.jar

This is the simple example to get the classpath configuration in your system by using the Java code. If you have any questions please write it in the comments section.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>