Reputation: 235
I am trying to distribute a JavaFX jar file containing alle maven dependencies. However my only builds which are working, have the maven dependencies extracted as .jar files.
My pom file contains following lines:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>groupId</groupId>
<artifactId>MusikPlayer</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org</groupId>
<artifactId>jaudiotagger</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies>
Is there any way to distribute the JavaFX jar file with all maven dependencies within, sothat i only have 1 jar file?
Upvotes: 1
Views: 1183
Reputation: 457
I highly suggest upgrading to openJFX. I see you're using JavaFX bundled in JDK 1.8. Please consider doing that below as it will not only do what you're looking for (which is compiling your project into a jar), but also will improve your application with the new JavaFX functionalities, improved performance, fixed bugs, etc.
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>${javafx.version}</version>
<classifier>win</classifier>
</dependency>
Replace
11
Where it is notated as
${javafx.version}
Inside build>plugins:
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>${javafx.mainClass}</mainClass>
</configuration>
</plugin>
Replace
${javafx.mainClass}
With your main class which extends Application and has a main method. Note that it has to be a full qualified name, example:
com.app.Main
After pasting all of it, just go to terminal and run
mvn clean install
Your runnable jar will be inside target folder (which is auto-generated by maven).
To run your jar simply double-click on it or run with
java -jar "your_jar_name.jar"
Note that you don't have to remove anything from your pom.
Hope that helps!
Upvotes: 0
Reputation: 7526
What you need is the javafx-maven-plugin
:
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.4.0</version>
<configuration>
<mainClass>your.package.with.Launcher</mainClass>
</configuration>
</plugin>
With your.package.with.Launcher
being you Application
class. This plugin also allows you to create native bundles. For ease of use take a look at their page to quickly pull together the plugin configuration for the most common cases.
With the above configuration you can build the all in one executable jar file with mvn jfx:jar
. The jar file will be located in target/jfx/app
.
Upvotes: 0