HOW SHOULD WE SET CLASSPATH URL'S TO URLCLASSLOADER?

Jessica James

Total Post:16

Points:114
Posted by  Jessica James
Java 
 495  View(s)
Ratings:
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/
  1. Mayank Tripathi

    Post:397

    Points:3117
    Re: How should we set classpath URL's to URLClassLoader?

    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/");
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!