Forum Stats

  • 3,874,198 Users
  • 2,266,682 Discussions



User_WL6FP Member Posts: 6 Red Ribbon
edited Apr 25, 2018 7:59AM in Java Programming


I'm getting ClassNotFoundException error in this code below.

String url ="http://<some-path>/app.jar";

URL[] classLoaderUrls = new URL[]{new URL(url)};


ClassLoader cl = new URLClassLoader(classLoaderUrls);

Class<?> beanClass = cl.loadClass(""); // Throwing ClassNotFoundException although this class is present in the JAR in the  fully qualified package name.

Any clue what to fix here ?


  • Unknown
    edited Apr 24, 2018 1:14PM
    Any clue what to fix here ?

    Haven't used that class to load jars.

    See if you can get it to work using the JarClassLoader and the url syntax shown in The Java Tutorials examples.

    The JarURLConnection class and JAR URLs

    The getMainClassName method uses the JAR URL format specified by the class. The syntax for the URL of a JAR file is as in this example:jar:!/ 

    The terminating !/ separator indicates that the URL refers to an entire JAR file.

  • User_WL6FP
    User_WL6FP Member Posts: 6 Red Ribbon
    edited Apr 25, 2018 7:59AM

    Okay is where I'm stuck in JarURLConnection.

    String className=""   // This class  has no main method but it is in the JAR

    String JAR_URL="jar:"+<some_http_url>+"!/";

    URL jarUrl = new URL(JAR_URL);

    JarURLConnection jarURLConnection = (JarURLConnection)jarUrl.openConnection();

    Class<?> beanClass = jarURLConnection.loadClass(className); // This does not even compile since there is no loadClass method in JarURLConnection

    I'd appreciate if you provide  tested  solution to this problem.  I have researched in google and tested with other stream reading approaches but none was able to load class.

    my goal is :   I  want to load a specific given class from a JAR.  and this JAR  file is accessible  in http .

    Is it possible at all ?  any working solution  ?

This discussion has been closed.