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.

 * 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");


/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 *

Pin It on Pinterest

Share This

Share this post with your friends!