JDK11/JavaFX:如何在没有构建/依赖关系管理的情况下制作一个胖 jar? [英] JDK11/JavaFX: How do I make a fat jar without build/depdency management?

查看:28
本文介绍了JDK11/JavaFX:如何在没有构建/依赖关系管理的情况下制作一个胖 jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为不用说,我应该能够将 Oracle 自己的 JDK 与 JavaFX(来自 gluonhq)一起使用来构建用户可以直接使用的可分发 jar 文件.

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.

经过详尽的搜索、大量阅读(过去几个月 24 小时或更长时间),最后是这个 Google 搜索查询:

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

我绝对在路的尽头.为什么会有这么多工作?我如何构建 JavaFX 应用程序并将其提供给想要实际使用它的人而不知道如何使用应用程序本身?

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?

推荐答案

这个问题已经回答了几次 MavenGradle.构建工具比在命令行上做事情更容易,不仅仅是因为依赖管理.

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.

由于您专门询问命令行,因此这里已经记录了完整的指令集:https://openjfx.io/openjfx-docs/#modular.

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 from CLI 部分涵盖了来自命令行的 JavaFX 非模块化项目,并为您提供了创建旧的经典胖 jar 的整套指令,其中包含所有依赖项,包括JavaFX 的,捆绑在一起.

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:

警告:这是一个不鼓励的、乏味的、容易出错的手动过程,应该通过使用 Maven 的 shade 插件或 Gradle 的 jar 任务来避免,以防 jlink 不适用.

Warning: This is a discouraged tedious error-prone manual process that should be avoided by using the Maven's shade plugin or the Gradle's jar task, in case jlink is not applicable.

获得fat jar(它可以是跨平台的)后,您可以分发它,并且您的用户需要安装并运行Java:

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 from CLI 部分涵盖了命令行中的 JavaFX 模块化项目,并在分发方面参考了 jlink 命令的使用,因为它创建了自定义您可以发送给用户的图像.它不是一个胖 jar,但它允许您向您的用户发送一个 zip 文件,只需解压缩并运行:

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

在这种情况下,您的用户甚至不需要安装 Java.

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

但是,如果您仍然想用模块化应用程序做一个胖罐子,您仍然可以应用与非模块化应用程序完全相同的说明.在这种情况下,您可能必须删除 module-info.java 文件,因为此时它实际上没有意义.

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.

您还有更多的选择来分发您的应用程序.

You still have a few more options to distribute your application.

自定义 Java+JavaFX 图像

同一文档中的另一个选项,自定义 JDK+JavaFX 映像部分,解释了如何创建自己的包含 JavaFX 的JDK".然后你将像往常一样在 Java 8 中生成你的 jar 并且你将能够运行它:

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

请注意,已经有一些 JDK 发行版捆绑了 JavaFX,例如一个.

Note that there are already some JDK distributions that bundle JavaFX, like this one.

jpackage

jpackage 工具还没有,但有一个早期访问:http://jdk.java.net/jpackage/,即使用Java 13-internal.现有的 文档 解释了生成自定义映像或安装程序所需的命令行选项.

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.

请注意,您仍然可以使用 JavaFX 11 或 12.

Note that you can still use JavaFX 11 or 12 with this.

构建工具

最后,您仍然可以决定使用构建工具(Maven 或 Gradle),这将在很多方面真正帮助您.请参阅上面的任何链接问题.

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:如何在没有构建/依赖关系管理的情况下制作一个胖 jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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