Adrian Chlubek
Adrian Chlubek

Reputation: 39

Including JAR within a JAR makes class don't see jar content

I'm merging jar files and one main class into one jar. The problem is that my main class use those jars, and if it's in one jar it just throws it cannot find classes definitions. How to make class see jars in jar?

Upvotes: 0

Views: 171

Answers (1)

M Abbas
M Abbas

Reputation: 6479

The Java Launcher$AppClassLoader does not know how to load classes from a Jar inside a Jar. What you need is a custom classloader that knows how to load classes and resources from a jars inside an archive, instead of from jars in the filesystem.

You can take a look on one-jar, it lets you package a Java application together with its dependency Jars into a single executable Jar file.

JarClassLoader can also load classes, native libraries and resources from the top JAR and from JARs inside the top JAR.

Another solution (The very ugly one) would be to explode JAR contents inside your jar.

Upvotes: 1

Related Questions