JavaFX 8 - How to build EXE with Maven & INNO

隐身守侯 提交于 2019-12-03 00:29:58

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 ;)

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>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!