Discussions
Categories
- 197.1K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 555 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 468 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
ClassNotFoundException

Hi,
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("com.app.MyClass"); // Throwing ClassNotFoundException although this class is present in the JAR in the fully qualified package name.
Any clue what to fix here ?
Answers
-
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.
https://docs.oracle.com/javase/tutorial/deployment/jar/jarclassloader.html
The JarURLConnection class and JAR URLs
The
getMainClassName
method uses the JAR URL format specified by thejava.net.JarURLConnection
class. The syntax for the URL of a JAR file is as in this example:jar:http://www.example.com/jarfile.jar!/The terminating
!/
separator indicates that the URL refers to an entire JAR file. -
Okay ..here is where I'm stuck in JarURLConnection.
String className="com.app.MyClass" // 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 ?