javafx独立包

时间:2015-10-07 07:47:37

标签: javafx-2

我通过将以下代码段复制到build.xml文件中,使用netbeans创建了javafx独立应用程序

<target name ="-post-jfx-deploy">
<fx:deploy width="${javafx.run.width}" height="${javafx.run.height}"
           nativeBundles="all"
           outdir="${basedir}/${dist.dir}" outfile="${application.title}">
    <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
    <fx:resources>
        <fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/>
    </fx:resources>
    <fx:info title="${application.title}" vendor="${application.vendor}"/>
</fx:deploy>
</target>

我有x64位版本的jdk环境,所以它创建了仅在x64位版本的Windows或操作系统中运行的应用程序。任何人都可以告诉我应该如何更改deploy方法以使应用程序在x86位系统上运行。默认情况下,netbeans占用了64位版本的jdk环境

1 个答案:

答案 0 :(得分:0)

您可以通过以下方式将Maven与Ant结合使用:

  • 为JDK定义Maven工件
  • 使用maven-dependency-plugin
  • 使用unzip Ant任务
  • 使用<fx:platform>

为JDK定义Maven工件

为JDK x86和JDK x64定义Maven工件。这可能听起来很奇怪,但在持续集成环境中思考,它根本就没有意义。

您只需压缩普通的JDK文件夹并将其部署为Maven工件。

然后您的Maven项目将取决于:

<properties>
    <jdk.version>1.8.112</jdk.version>
    <!-- can be '64' or '32' -->
    <cpu.arch>64</cpu.arch>
</properties>

</dependencies>
    <!-- other dependencies goes here -->

    <dependency>
        <groupId>com.my.company</groupId>
        <artifactId>jre-linux-${cpu.arch}</artifactId>
        <version>${jre.version}</version>
        <type>zip</type>
        <scope>runtime</scope>
    </dependency>
</dependencies>

注意:我在Debian上运行,但它也完全适用于Windows环境。

使用maven-dependency-plugin

添加maven-dependency-plugin。它会将所有依赖项(包括在依赖项部分中定义的JDK zip文件)复制到/target/dist/lib文件夹。 我们很快就会用到它。 插件配置如下:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>install</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <includeScope>runtime</includeScope>
                <outputDirectory>${application.dist}/lib</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>true</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>

使用unzip Ant任务

现在,在JavaFX Ant任务之前,您必须告诉Ant将JDK依赖项提取到文件夹中。 必须将 BEFORE 设置为捆绑JavaFX应用程序的任务。

<unzip src="${application.dist}/lib/jdk-linux-${cpu.arch}-${jdk.version}.zip"
                                       dest="${extra.dir}/jdk"/>

使用<fx:platform>

最后,在您的<fx:deploy>代码中,您必须添加<fx:platform>子代码,并将basedir属性添加为您之前的jdk文件夹,例如:

<fx:deploy ...>
    <fx:platform javafx="8.0+" basedir="${extra.dir}/jdk" />
</fx:deploy>

Maven日志将与此类似:

[INFO] --- maven-antrun-plugin:1.7:run (default) @ my-app ---
[INFO] Executing tasks

main:
    [unzip] Expanding: /home/danilo/development/temp/my-app/target/dist/lib/jdk-linux-64-1.8.112.zip into /home/danilo/development/temp/my-app/target/extras/jdk
Using base JDK at: /home/danilo/development/temp/my-app/target/extras/jdk/jre
Using base JDK at: /home/danilo/development/temp/my-app/target/extras/jdk/jre
Creating app bundle: /home/danilo/development/temp/my-app/target/dist/bundles/my-app
Debian packages should specify a license.  The absence of a license will cause some linux distributions to complain about the quality of the application.
  Using default package resource [menu icon]  (add package/linux/my-app.png to the class path to customize)
  Using default package resource [Menu shortcut descriptor]  (add package/linux/my-app.desktop to the class path to customize)
  Using default package resource [DEB control file]  (add package/linux/control to the class path to customize)
  Using default package resource [DEB preinstall script]  (add package/linux/preinst to the class path to customize)
  Using default package resource [DEB prerm script]  (add package/linux/prerm to the class path to customize)
  Using default package resource [DEB postinstall script]  (add package/linux/postinst to the class path to customize)
  Using default package resource [DEB postrm script]  (add package/linux/postrm to the class path to customize)
  Using custom package resource [DEB copyright file]  (loaded from package/linux/copyright)
dpkg-deb: construindo pacote 'my-app' em '/home/danilo/development/temp/my-app/target/dist/bundles/my-app-1.0.deb'.
Package (.deb) saved to: /home/danilo/development/temp/my-app/target/dist/bundles/my-app-1.0.deb
  Config files are saved to /tmp/fxbundler8773603423891700338/linux. Use them to customize package.
Bundler RPM Bundle skipped because of a configuration problem: Can not find rpmbuild {0} or newer.  
Advice to fix:   Install packages needed to build RPM, version {0} or newer.
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8:34.875s
[INFO] Final Memory: 22M/253M
[INFO] ------------------------------------------------------------------------

结论

当您需要在x86环境中交付应用程序时,只需在构建时覆盖cpu.arch Maven属性:

mvn -Dcpu.arch=32 clean install

现在,您可以更轻松地设置持续集成。例如,如果您使用Jenkins CI,则可以创建2个不同的作业并根据需要运行它。

我将整个项目推送到Github存储库。您可以在此处查看:https://github.com/daniloguimaraes/javafx-multiple-jre-versions