Home > DeveloperSection > Forums > How should we set classpath URL's to URLClassLoader?
Jessica James
Jessica James

Total Post:16

Points:114
Posted on    December-03-2015 12:08 AM

 Java Java 
Ratings:


 1 Reply(s)
 264  View(s)
Rate this:
I have this piece of code:

URLClassLoader tmp = new URLClassLoader(new URL[] { getClassPath() });
private static URL getClassPath() {
    return new URL("/home/rudik/workspace/cl/target/classes/");
}
I got /home/rudik/workspace/cl/target/classes/ from Arrays.toString(((URLClassLoader) MyClass.class.getClassLoader()).getURLs()) execution.

When I execute it I get this exception:

java.net.MalformedURLException: no protocol: /home/rudik/workspace/cl/target/classes/


Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Supported
Posted on    December-03-2015 12:19 AM

You don't pass a URL string to the URL constructor. In your case it should be
private static URL getClassPath() {
    return new URL("file:///home/rudik/workspace/cl/target/classes/");
}

Don't want to miss updates? Please click the below button!

Follow MindStick