Java: create jar executable with dependent inline jars

I created an executable JAR with a manifest:

Manifest-Version: 1.0 Main-Class: MyClass Class-Path: lib/ext.jar 

I can successfully run this JAR if I have a lib folder with dependent ext.jar in the .jar folder.

I would like to embed ext.jar in my executable JAR to run it anywhere without creating a lib folder. This would allow the JAR file to be autonomous, including all its dependencies.

Is there any way to do this?

+4
source share
2 answers

By default, the Java class loader cannot find the inline phrase in the jar file. You will need to configure your Java program to use a class loader that can handle embedded jar files. As I know, I have not seen anyone in any open source libraries, so you may need to write them yourself.

In addition, you can extract all jar files and merge the contents into a single jar file.

A clean way to combine multiple cans? Ant preferred

+3
source

Java does not have ready-made support for embedding jars in jars. This can be achieved by writing a custom class loader or using a tool that has already been written for this purpose: Fat Jar .

+2
source

Source: https://habr.com/ru/post/1383659/


All Articles