问题
I have not been able to successfully find a working solution on how to configure Maven to build an EXE from JavaFX with Maven.
Projects set up with E(fx)clipse using the build.fxbuild work great, however I would prefer to have a maven project, with dependent modules rather the basic ANT builds.
I have seen some comments on ZENJAVA - but it appears that plug in has lost all traction and is pretty much dead.
Is there anything out there that can bundle an EXE from Maven? My project is an enterprise project which will have several projects, and lots of dependencies - so I was hoping for a simple, effective way to manage all of that.
Thanks
回答1:
the plugin is NOT dead, just the official website was taken down due to the costs it produced.
Just look at the git-repository for further details: https://github.com/javafx-maven-plugin/javafx-maven-plugin
We have some sample configurations within our testing-folder: https://github.com/javafx-maven-plugin/javafx-maven-plugin/tree/master/src/it
To just build the EXE-installer, you can specify an specific bundler (from version 8.1.3 and up).
To use the plugin, just put this into your build-plugins:
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.3-SNAPSHOT</version>
<configuration>
<mainClass>com.your.amazing.mavenized.javafxapplication</mainClass>
<bundler>EXE</bundler>
</configuration>
</plugin>
disclaimer: i'm one of the maintainer of that plugin ;)
回答2:
I was able to do this with javafx-ant tasks.
http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 com.myapp.application myApp jar 1.0-SNAPSHOT MyApp http://www.somecompany.com
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<javafx.version>8.0</javafx.version>
</properties>
<repositories>
<repository>
<id>repo</id>
<url>file://${project.basedir}/lib/repo</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<!-- copy all dependencies of your app to target folder -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<configuration>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Main-Class>com.myApp.MainClass</Main-Class>
<implementation-version>1.0</implementation-version>
<JavaFX-Application-Class>com.myApp.MainClass</JavaFX-Application-Class>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<!-- copy the properties files to the root location -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources-1</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/properties</outputDirectory>
<resources>
<resource>
<directory>properties</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<!-- define the deploy ANT task -->
<taskdef name="jfxdeploy" classname="com.sun.javafx.tools.ant.DeployFXTask"
classpathref="maven.plugin.classpath" />
<!-- define the JarSing ANT task -->
<!-- taskdef name="jfxsignjar" classname="com.sun.javafx.tools.ant.FXSignJarTask"
classpathref="maven.plugin.classpath" / -->
<jfxdeploy outdir="${project.build.directory}/deploy"
outfile="${build.finalName}" nativeBundles="all">
<info title="${project.name}" />
<!-- set the main class of your applcation -->
<application name="${project.name}"
mainClass="com.myApp.MainClass" />
<resources>
<fileset dir="${project.build.directory}" includes="*.jar" />
<fileset dir="${project.build.directory}/dependency"
includes="*.jar" />
<fileset dir="${project.build.directory}/properties" includes="*.properties"/>
</resources>
<!-- set your jvm args -->
<platform>
<jvmarg value="-Xms512m" />
<jvmarg value="-Xmx1024m" />
</platform>
</jfxdeploy>
<!-- you need to generate a key yourself -->
<!--jfxsignjar destdir="${project.build.directory}/deploy" keyStore="path/to/your/keystore"
storePass="yourPass" alias="yourAlias" keyPass="keyPass"> <fileset dir="${project.build.directory}/deploy"
includes="*.jar" /> </jfxsignjar -->
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ant-javafx</artifactId>
<version>${javafx.version}</version>
<systemPath>${java.home}/../lib/ant-javafx.jar</systemPath>
<scope>system</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
<finalName>CashReceipts</finalName>
</build>
<dependencies>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.40.9</version>
</dependency>
<dependency>
<groupId>customJar</groupId>
<artifactId>custom</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
来源:https://stackoverflow.com/questions/31273829/javafx-8-how-to-build-exe-with-maven-inno