问题描述
我想不言而喻,我应该能够使用Oracle自己的JDK和JavaFX(来自gluonhq)来构建可分发的jar文件,供用户使用.
经过详尽的搜索,大量阅读(过去几个月中24小时或更长时间),最后是这个Google搜索查询:
how to make a fat jar -maven -gradle -scala -eclipse -ant -docker -hadoop -netbeans -jerkar -phy -mozni -yogurt -pizza - throwing -python -bacon
我绝对是路的尽头.为什么在地球上这么多工作呢?我该如何构建JavaFX应用程序,并将其提供给想要实际使用它的人,而又不知道如何使用该应用程序本身呢?
对于和 Gradle .构建工具使事情比在命令行上做起来容易得多,不仅是因为依赖管理.
由于您是专门询问命令行的,因此这里已经有完整的说明文档: https://openjfx.io/openjfx-docs/#modular .
非模块化应用
Non-Modular from CLI
部分涵盖了命令行中的JavaFX非模块化项目,并为您提供了创建旧的经典Fat jar的全部指令集,其中所有依赖项(包括JavaFX依赖项)都捆绑在一起./p>
有一条警告提示您不要使用此过程:
获得胖子罐(它可以是跨平台的)后,就可以分发它,并且您的用户需要安装并运行Java:
java -jar myFat.jar
模块化应用
Modular from CLI
部分从命令行涵盖JavaFX模块化项目,并在分发方面引用了jlink
命令的用法,因为它创建了可以发送给用户的自定义图像.它不是一个胖子,但它允许您向用户发送一个zip,而该zip只需解压缩即可运行:
hellofx/bin/java -m hellofx/hellofx.HelloFX
在这种情况下,您的用户甚至不需要安装Java.
通过一些额外的工作,您还可以创建一个批处理,以便您可以运行:
hellofx
但是,如果您仍然想使用模块化应用程序制作胖子,则仍然可以应用非模块化应用程序中的完全相同的说明.在这种情况下,您可能必须删除module-info.java
文件,因为此时它实际上没有任何意义.
其他选项
您还有其他一些分发应用程序的选项.
自定义Java + JavaFX图像
同一文档的定制JDK + JavaFX图像"部分中介绍了另一个选项,该选项说明了如何创建自己的包含JavaFX的"JDK".然后,您将像在Java 8中一样生成jar,并可以使用以下命令运行它:
/path/to/custom/java -jar myFat.jar
请注意,已经有一些JDK发行版捆绑了JavaFX,例如一个 a>.
jpackage
jpackage
工具尚不存在,但是可以进行早期访问: http://jdk.java .net/jpackage/,即内部使用Java 13.退出的文档解释了生成定制映像或安装程序所需的命令行选项.
请注意,您仍然可以与此同时使用JavaFX 11或12.
构建工具
最后,您仍然可以决定使用构建工具(Maven或Gradle),这实际上会在很多方面为您提供帮助.请参阅上面的任何链接的问题.
I think it goes without saying that I should be able to use Oracle's own JDK with JavaFX (from gluonhq) to build a distributable jar file that users can just USE.
After an exhaustive search, much reading (24 hours or more over the last few months)and finally this Google search query:
how to make a fat jar -maven -gradle -scala -eclipse -ant -docker -hadoop -netbeans -jerkar -phy -mozni -yogurt -pizza - throwing -python -bacon
I'm absolutely at the end of the road. Why on earth is this so much work? How can I build a JavaFX application and give it to people that want to actually use it without knowing anything else except how to use the application itself?
This has been answered a few times already for Maven and Gradle. Build tools make things way easier than doing it on command line, and not only because of the dependency management.
Since you ask specifically about command line, there is already a full set of instructions documented for it here: https://openjfx.io/openjfx-docs/#modular.
Non modular App
The section Non-Modular from CLI
covers JavaFX non-modular projects from command line, and gives you the whole set of instructions to create an old classic fat jar, where all the dependencies, including the JavaFX ones, are bundled all together.
There is a note that warns you not to use this procedure:
After you get the fat jar (it can be cross-platform), you can distribute it, and your user will need to have Java installed and run:
java -jar myFat.jar
Modular App
The section Modular from CLI
covers JavaFX modular projects from command line, and refers to the use of the jlink
command, in terms of distribution, as it creates a custom image that you can send to your users. It is not a fat jar, but it will allow you sending a zip to your user that needs only to be unzipped and run like:
hellofx/bin/java -m hellofx/hellofx.HelloFX
In this case your user won't even need to have Java installed.
And with a little bit of extra work you can also create a batch, so you can run:
hellofx
However, if you still want to do a fat jar with a modular app, you can still apply the exact same instructions from the non-modular apps. In this case, you will probably have to remove the module-info.java
file, as it doesn't really makes sense at this point.
Other options
You still have a few more options to distribute your application.
Custom Java+JavaFX image
Another option, covered in the same document, section Custom JDK+JavaFX image, explains how to create your own "JDK" that includes JavaFX. Then you will produce your jar as usual in Java 8 and you will be able to run it with:
/path/to/custom/java -jar myFat.jar
Note that there are already some JDK distributions that bundle JavaFX, like this one.
jpackage
jpackage
tool is not there yet, but there is an early access: http://jdk.java.net/jpackage/, that is using Java 13-internal. The exiting documentation explains what are the command line options you need to produce a custom image or an installer.
Note that you can still use JavaFX 11 or 12 with this.
Build tools
And finally, you can still decide to use build tools (Maven or Gradle), that will really help you in many ways. See any of the linked questions above.
这篇关于JDK11/JavaFX:如何在没有构建/依赖管理的情况下制作胖子呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!