如何为没有本机安装程序的JavaFX应用程序创建可运行的jar [英] How to make a runnable jar for an application that uses JavaFX without native installers

查看:183
本文介绍了如何为没有本机安装程序的JavaFX应用程序创建可运行的jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可以在从Eclipse导出为runnable jar之后使用java -jar blah.jar运行,并让它将所需的库打包到生成的JAR中。

I have a application that worked just fine to be run with "java -jar blah.jar" after exporting as a runnable jar from Eclipse and letting it "Package required libraries into generated JAR".

我添加了一些JavaFX代码来弹出Web浏览器。现在似乎不可能制作一个可以在小型Java版本中运行的可运行jar。当我将它导出为可运行的jar时,它会复制到我的次要版本特有的jfxrt.jar中。如果我使用java -jar blah.jar为完全匹配的java版本(jdk1.7.0_17)运行此jar,那么它工作正常,但如果我使用一个稍微更新(jdk1.7.0_45)然后它无法解决swingx上课正确。 写一次在任何地方运行非常多。

I added some JavaFX code to pop up a web browser. Now it seems it is impossible to make a runnable jar that works across minor Java versions. When I export it as a runnable jar, it copies in jfxrt.jar that is specific to my minor version. If I run this jar using "java -jar blah.jar" for the exact matching java version (jdk1.7.0_17) then it works fine, but if I use one slightly newer (jdk1.7.0_45) then it fails to resolve swingx classes properly. So much for "write once run anywhere".

我尝试使用JavaFX ant任务,但我无法完成实际打包从属jar的任务。这实际上并不包括它创建的jar中的fx:resources jar,就像魔术eclipse将所需的库包装到生成的JAR中一样:

I tried to use the JavaFX ant tasks but I can't get the task to actually package up the dependent jars. This doesn't actually include the fx:resources jars in the jar it creates, like the magic eclipse "package required libraries into generated JAR" does perfectly:

<fx:jar destfile="${dist}/${dist.jar}"> 
        <fx:application id="BlahTesterApp" 
            mainClass="blah.MainClass" 
            toolkit="swing"/> 

        <fileset dir="${build}"/> 

        <fx:resources> 
            <fx:fileset dir="${lib}" includes="**/*.jar" />
        </fx:resources>

        <manifest> 
            <attribute name="Implementation-Vendor" value="My Team"/>
            <attribute name="Implementation-Title" value="Tester App"/> 
        </manifest> 
    </fx:jar> 

似乎只能创建我不想要的本地捆绑。我不想让用户在以前能够运行darn jar时安装rpm或deb。

And seems to only be able to create "native bundles" which I don't want. I don't want to make users install an rpm or a deb when they used to just be able to run the darn jar.

我不明白为什么Oracle有在这里介绍自己神奇的额外部署层。难道他们不希望人们使用JavaFX吗?

I don't understand why Oracle had to introduce its own magical extra layer of deployment complexity here. Don't they want people to USE JavaFX?

推荐答案

JavaFX包装替代品


  1. 关注 e(fx )clipse教程,用于使用Eclipse为JavaFX应用程序创建可执行jar文件。

  2. Oracle java打包ant任务和javafxpackager工具可以创建可执行jar(在Oracle文档中有描述)如独立应用程序)。如果你不能使用这些工具生成这样的jar,那么你可能没有正确使用这些工具。

  3. 需要最低版本的Java 8,其中jfxrt.jar(即JavaFX类)是在引导类路径上。

  4. 使用第三方构建工具链,例如 JavaFX Maven插件 JavaFX Gradle插件

  1. Follow the e(fx)clipse tutorial for creating an executable jar file for a JavaFX application using Eclipse.
  2. The Oracle java packaging ant tasks and javafxpackager tool can create executable jars (described in the Oracle documentation as standalone applications). If you cannot generate such jars using the tools, then you are likely not using the tools correctly.
  3. Require a minimum version of Java 8, where jfxrt.jar (i.e. the JavaFX classes) is on the boot class path.
  4. Use a 3rd party build tool chain such as the JavaFX Maven plugin or the JavaFX Gradle plugin.

自从您使用Eclipse以来,建议您使用替代(1),e(fx)clipse打包。

Alternative (1), e(fx)clipse packaging, is recommended for you since you are using Eclipse.

建议

永远不要尝试包含Java平台库(例如jfxrt。 jar)与您的应用程序。您在互联网上找不到的指南应该指示您做这样的事情(由于您在问题中概述的次要版本问题之间明显不兼容)。此规则的唯一例外是,如果您正在构建一个不依赖于预先安装的JRE(您不是)的自包含,本机安装的应用程序。

Never try to include Java platform libraries (such as jfxrt.jar) with your application. No guide you find on the internet should ever instruct you to do such a thing (due to the obvious incompatibility between minor version issues you outlined in your question). The only exception to this rule would be if you are building a self-contained, native installed application that doesn't rely on a pre-installed JRE (which you aren't).

这篇关于如何为没有本机安装程序的JavaFX应用程序创建可运行的jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆