Search code examples
javaantjavafx-2packagingexecutable-jar

How to get Executable javafx jar bundled with dependent jars?


I have made one javafx application form which I get an executable jar as output. Now my javafx application is dependent on two 3rd party jars like commons.io.2.4.jar.

Presently to run my application, I have to keep these dependent jars in classpath of my executable jar like this

--------Application.jar
----------[Classpath Folder]\dependend.jar files

But I want all dependent jars to get bundled in my executable jar itself.

Since javafx uses ant build I tried using

 <jar destfile="application.jar">
        <zipfileset src="Dependent.jar" />
 </jar>

but after bundling all dependent jars I am not getting executable jar. I don't know where the problem lies.

I also tried <fx:jar> </fx:jar> tags for the same, but not able to figure out how to exactly achieve my requirement.

This is how manifest file somewhat looks like:

Manifest-Version: 1.0
implementation-vendor: dhruv1767
JavaFX-Version: 2.2
implementation-title: LogsDeObfuscator
implementation-version: 1.0
JavaFX-Application-Class: com.liaison.controller.LogsDeObfuscator
JavaFX-Class-Path: lib/allatori.jar lib/commons-io-2.4.jar
Created-By: JavaFX Packager
Main-Class: com/javafx/main/Main

Name: com/javafx/main/Main.class
SHA-256-Digest: j0IuLabX3l0TgeO1+UqESD6fWA09lNsuiTtr4eue1HU=

Name: com/liaison/controller/LogsDeObfuscator.class
SHA-256-Digest: AysvgvCJeJoRdCpqu1xC8JDKttGWUQR4ce8jVW/kLDY=

Name: com/liaison/controller/Delta.class
SHA-256-Digest: TkQcfU1YWr6UwkiIj2IJpFi4UirQK7pDL26pVnAjVYM=

Solution

  • One thing to watch out for is if any of the dependent JARs themselves contain a manifest.

    <jar destfile="application.jar">
        <zipfileset src="Dependent.jar" excludes="META-INF/MANIFEST.MF/>
    </jar>