简体   繁体   English

如何使用 Java 11 运行已编译的 Java 8 JavaFX 应用程序 jar?

[英]How to run compiled Java 8 JavaFX application jar using Java 11?

I have an executable jar file compiled with Java 8 and containing a JavaFX application called app.jar .我有一个用 Java 8 编译的可执行文件 jar,其中包含一个名为app.jar的 JavaFX 应用程序。

When I had Java 8 installed I could run it simply with java -jar app.jar .当我安装了 Java 8 后,我可以简单地使用java -jar app.jar运行它。

Now I only have Java 11 installed and running the command above generates the following error:现在我只安装了 Java 11 并且运行上面的命令会产生以下错误:

Error: Could not find or load main class <...>
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

because Java 11 no longer includes JavaFX.因为 Java 11 不再包括 JavaFX。

So I looked into installing JavaFX. openjfx.org provides JavaFx in two forms: an SDK and in JMOD files.所以我研究了安装 JavaFX。openjfx.org 在两个forms中提供了 JavaFx:一个 SDK 和 JMOD 文件。

I figure I don't need the SDK because I am not creating a JavaFX but merely running one.我想我不需要 SDK 因为我不是在创建 JavaFX 而只是运行一个。 This leaves the JMOD files as the remaining options.这使 JMOD 文件成为剩余的选项。

However, the Oracle documentation on JMODs says: "The JMOD file format let's you aggregate files other than.class files, metadata, and resources. This format is transportable but not executable, which means that you can use it during compile time or link time but not at run time," so it does not seem like they are going to help me running an application.然而, 关于 JMOD 的 Oracle 文档说:“JMOD 文件格式让您聚合除 .class 文件、元数据和资源之外的文件。这种格式可传输但不可执行,这意味着您可以在编译时或链接时使用它但不是在运行时,”所以他们似乎不会帮助我运行应用程序。

Questions:问题:

  • How can I run app.jar as defined above with a Java 11 runtime?如何使用 Java 11 运行时运行上面定义的app.jar
  • Is there any documentation explaining how to do this and, if so, where?是否有任何文档解释如何执行此操作,如果有,在哪里?

Seems like you've missed adding the PATH_TO_FX environment variable to your system.好像您错过了将 PATH_TO_FX 环境变量添加到您的系统。 You can find a guide on how to do that here:您可以在此处找到有关如何操作的指南:

If it's a Java 8 application, easiest option for you is simply getting Oracle JDK 8 and defining that as the JDK in system environment.如果它是一个 Java 8 应用程序,最简单的选择就是获取 Oracle JDK 8并将其定义为系统环境中的 JDK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM