【问题标题】:javafx self-contained packagejavafx 自包含包
【发布时间】:2016-01-04 08:23:43
【问题描述】:

我通过将以下 sn-p 复制到 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 或操作系统中运行的应用程序。谁能告诉我应该如何更改部署方法以使应用程序可在 x86 位系统上运行。默认netbeans占用64位版本的jdk环境

【问题讨论】:

    标签: javafx-2


    【解决方案1】:

    您可以通过以下方式将 Maven 与 Ant 结合起来:

    为 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 依赖项提取到一个文件夹中。 必须捆绑您的 JavaFX 应用程序的任务之前设置。

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

    使用&lt;fx:platform&gt;

    最后,在您的&lt;fx:deploy&gt; 标签中,您必须添加一个&lt;fx:platform&gt; 子标签,将basedir 属性添加为您之前的@​​987654340@ 文件夹,例如:

    <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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-27
      • 2016-12-16
      • 1970-01-01
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多