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.



About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

  • Smitha

    Thank you so much