Here's the problem:
After making some GUI application (NetBeans) in output directory (containing generated .jar file) also appeared a directory 'lib' with additional .jar. This jar is some extra library with classes, which path is added in manifest ("Class-Path: lib/bla.jar").

So I've used to pack my applications always intto a single .jar file, so it's easier to move, but with this one I've got a problem.

Without this .jar application gets error "ClassNotFoundException", so I want to load the classes from that jar in runtime as a resource. I've learned the way to load a single class by:

URL jar = getClass().getResource("lib/swing.jar");
URLClassLoader ucl = new URLClassLoader(new URL[] {jar});

And here's the question: how to load ALL of the classes in package 'org.jdesktop.layout' in that jar, because 'org.jdesktop.layout.*' doesn't work. Any way to explore this directory to get all of the paths like 'org.jdesktop.layout.GroupLayout' to load all classes?

Sry for a bit long post and waiting for advices. :)

6 Years
Discussion Span
Last Post by Zibo

This doesn't answer your question directly, but as an alternative, you can have the JVM load the classes from your jar file using

java -Djava.ext.dirs=lib\swing.jar; <your class here>

Indeed, it doesn't. Still looking for suggestions to solve my problem...


Thx, kramerd! That's exactly what I was looking for.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.