Intellij Javafx神器 - 你是怎么做到的? [英] Intellij Javafx artifact - how do you make it?
问题描述
我一直在努力将我的javafx应用程序转换为jar文件。我正在使用Java 1.7 update 7.。
I've been trying all day to turn my javafx application into a jar file. I'm using Java 1.7 update 7.
Oracle有一些信息,但它似乎散落在各处。 Intellij几乎正在完成这项工作,但我收到以下错误:
Oracle has some information, but it just seems scattered all over the place. Intellij is almost doing the job, but I get the following error:
java.lang.NoClassDefFoundError: javafx/application/Application
这似乎说我需要告诉java jfxrt.jar在哪里...如果我添加这个jar到我的类路径信息中的清单构建在intellij - ctrl + shift + alt + s - >工件 - >输出布局选项卡 - >类路径,然后我得到另一个错误:
Which seems to say that I need to tell java where the jfxrt.jar is... If I add this jar to my classpath info for the manifest build in intellij - ctrl+shift+alt+s -> Artifacts -> Output Layout tab -> Class Path, then I get another error:
Could not find or load main class com.downloadpinterest.code.Main
虽然在我的类路径中包含jfxrt.jar似乎很奇怪...
It seems strange to have to include jfxrt.jar in my class path though...
我也试过创建一个ant脚本,但我觉得IntelliJ有90%的方式 - 我需要一些帮助来弄清楚为什么我需要包含jfxrt.jar,以及为什么我的Main类没有找到(我猜我需要以某种方式将它添加到类路径中吗?)。
I've tried to create an ant script as well, but I feel like IntelliJ is 90% of the way there - and I just need a bit of help to figure out why I need to include jfxrt.jar, and why my Main class isn't being found (I'm guessing I need to add it to the classpath somehow?).
有谁能让我知道发生了什么?我有一个基本的gui,之前工作正常,但JavaFX似乎让生活变得复杂!
Could anyone clue me up as to what is happening? I had a basic gui before which worked fine, but JavaFX seems to be making life complicated!
推荐答案
你的假设是正确的,你需要将JavaFX添加到类路径。
它位于 [JDK] /jre/lib/jfxrt.jar
。
Your assumption is correct, you need to add JavaFX to the classpath.
It is located in [JDK]/jre/lib/jfxrt.jar
.
要在运行时提供JavaFX,可以将其与应用程序捆绑在一起,如 Oracle指南 或
使Java 7 Update 6成为您应用的要求,然后添加 [JAVA_HOME ] /lib/jfxrt.jar
在应用程序最方便的时候到类路径。
To provide JavaFX at runtime, you can bundle it with your application, illustrated in this Oracle guide or
make Java 7 Update 6 a requirement for your app, then add [JAVA_HOME]/lib/jfxrt.jar
to the classpath at the application's earliest convenience.
第一个选项意味着更多的工作,但绝对是确保所有用户都拥有相同版本的库 - 您也可以将JRE捆绑在一起。
第二个版本不提供这种确定性,但更容易实现。
The first option means more work for you, but makes absolutely sure that all users have the same version of the library - and you can bundle the JRE as well, while you are at it. The second version doesn't offer this certainty, but is easier to realize.
作为第二个选项的变体 - 如果捆绑JRE实际上是可能的对于您 - ,您也可以将它捆绑在您的发行版中,然后包含一个shell脚本/批处理文件/可执行包装程序,以使您的程序使用它。
这样,你可以从选项I中获得所有的确定性,而且选项II的难度只有适度提升。
As a variant to the second option - if bundling the JRE is actually possible for you - , you can also just bundle it in your distribution and then include a shell-scripts/batch-file/executable-wrapper to make your program use it. That way, you get all the certainty from option I with only a moderate boost in difficulty from option II.
这篇关于Intellij Javafx神器 - 你是怎么做到的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!