How to Print Classpath in Java


In this example, let’s see how to print out the current project classpath in Java.

Source Code

package com.beginner.examples;

import java.net.URL;
import java.net.URLClassLoader;

public class CurrentProjectClasspath {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ClassLoader cl = ClassLoader.getSystemClassLoader();

		URL[] urls = ((URLClassLoader) cl).getURLs();

		for (URL url : urls) {
			System.out.println(url.getFile());
		}
	}

}

Output:

/C:/Users/Administrator/Workspaces/MyEclipse%2010/objUrl/bin/

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments