Dhruv
Dhruv

Reputation: 10693

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=

Upvotes: 2

Views: 2170

Answers (3)

onebeartoe
onebeartoe

Reputation: 145

Give this a try:

http://www.zenjava.com/2012/11/24/from-zero-to-javafx-in-5-minutes/

Maven is required, but will make adding your Commons IO dependency a snap.

Following the directions, I was able to make an executable JAR and native installer for Ubuntu. Executable JAR generation is done with this command:

mvn jfx:build-jar

Get the example project from the link working. Then add the dependency to the POM file.

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
</dependency>

Then you can move your existing code to the Maven managed JavaFX project.

More details are on the link, but to generate a native installer run this command:

mvn jfx:build-native

Upvotes: 0

Ian Roberts
Ian Roberts

Reputation: 122364

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>

Upvotes: 1

Bipin Bhandari
Bipin Bhandari

Reputation: 682

I have face the same problem before i use exe4j for this i have added all the jars that are required and exe4j bundeled all them in one. This works for me. Make sure while adding the jar you add your Main classpath of main Jar.

Upvotes: 0

Related Questions