JavaFX 8 - How to build EXE with Maven & INNO

前端 未结 2 822
刺人心
刺人心 2021-02-04 14:57

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

相关标签:
2条回答
  • 2021-02-04 15:26

    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>
    

    0 讨论(0)
  • 2021-02-04 15:33

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

    0 讨论(0)
提交回复
热议问题