使用 JavaFX 在 Eclipse 中导出 Jar 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11172003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:23:59  来源:igfitidea点击:

Exporting Jar file in Eclipse using JavaFX

javaeclipsejavafx

提问by MCR

I have created an app using JavaFX 2.1 and wish to export it to be tested. This is the first "real" application I've made, so I have never done this before. In Windows 7 with eclipse I export a runnable jar, click on it, and nothing happens. Can someone tell me why this might be?

我已经使用 JavaFX 2.1 创建了一个应用程序,并希望将其导出以进行测试。这是我制作的第一个“真正的”应用程序,所以我以前从未这样做过。在带有 Eclipse 的 Windows 7 中,我导出一个可运行的 jar,单击它,但没有任何反应。有人能告诉我为什么会这样吗?

回答by jewelsea

Information on Packaging

包装信息

The app below was packaged using the command line javafxpackagertool. JavaFX also provides ant tasksfor packaging. I believe you could create an ant script for packaging and run it's tasks from inside Eclipse.

下面的应用程序是使用命令行javafxpackager工具打包的。JavaFX 还提供了用于打包的ant 任务。我相信您可以创建一个 ant 脚本来打包并从 Eclipse 内部运行它的任务。

The e(fx)clipseplugin provides integrated JavaFX packaging functionality by wrapping the JavaFX ant tasks. When developing JavaFX applications with Eclipse, use of e(fx)clipse is highly recommended.

E(FX)clipse插件提供通过包装JavaFX的蚂蚁任务集成JavaFX的包装的功能性。使用 Eclipse 开发 JavaFX 应用程序时,强烈建议使用 e(fx)clipse。

Verifying your JavaFX Packaging

验证您的 JavaFX 包装

  • Extract the jar files from the jar (jar xf <jarfile>).
  • Look at the extracted manifest (META-INF\MANIFEST.MF).
  • If the main class in the manifest is not com/javafx/main/Main then you have packaged the app wrong.
  • 从 jar ( jar xf <jarfile>) 中提取 jar 文件。
  • 查看提取的清单 ( META-INF\MANIFEST.MF)。
  • 如果清单中的主类不是 com/javafx/main/Main,那么您打包的应用程序错误。


C:\dev\javafx\willow\dist>jar xf willow.jar

C:\dev\javafx\willow\dist>type MANIFEST.MF
Manifest-Version: 1.0
JavaFX-Version: 2.1
JavaFX-Application-Class: org.jewelsea.willow.Willow
JavaFX-Class-Path: lib\image4j.jar lib\PDFRenderer-0.9.1.jar
Created-By: JavaFX Packager
Main-Class: com/javafx/main/Main

C:\dev\javafx\willow\dist>java -jar willow.jar

For your manifest the JavaFX-Application-Classentry will vary and the JavaFX-Class-Pathattribute is probably not needed.

对于您的清单,JavaFX-Application-Class条目会有所不同,并且JavaFX-Class-Path可能不需要该属性。

The example jar I used can then be run from the command line using java -jar <jarfile>.

我使用的示例 jar 然后可以从命令行使用java -jar <jarfile>.

回答by tomsontom

Like mentioned by the jewelsea e(fx)clipseprovides you an export wizard which uses the ant tasks provided by JavaFX. You can find a step by step tutorial at https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial1

就像jewelsea e(fx)clipse提到的那样,它为您提供了一个使用JavaFX 提供的ant 任务的导出向导。您可以在https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial1找到分步教程