简体   繁体   English

使用 javaFx 和 Intellij IDEA 构建到 jar 时缺少依赖项

[英]Missing dependencies when building to jar with javaFx and intellij IDEA

I am trying to build my project to a runnable jar in intellij IDEA;我正在尝试在 intellij IDEA 中将我的项目构建为一个可运行的 jar; I am using javaFx for the GUI.我在 GUI 中使用 javaFx。 I have successfully run/built the project multiple times through development but now I have created an artifact as followed in another stackoverflow post and this didn't include the javafx dependency even though I selected it to and it's in the build path, My message is: Error: JavaFX runtime components are missing, and are required to run this application even though I have added the dependencies in build and to the environment variables.我已经通过开发成功地多次运行/构建了该项目,但现在我在另一个stackoverflow 帖子中创建了一个工件,尽管我选择了它并且它在构建路径中,但它不包含 javafx 依赖项,我的消息是: Error: JavaFX runtime components are missing, and are required to run this application即使我已在构建和环境变量中添加了依赖项Error: JavaFX runtime components are missing, and are required to run this application Is there a solution?有解决办法吗?

Thanks谢谢

I had the same error message when trying to run a JAR file created with JavaFX 11 in IntelliJ.尝试在 IntelliJ 中运行使用 JavaFX 11 创建的 JAR 文件时,我收到了相同的错误消息。

You're just missing two additional steps:您只是缺少两个额外的步骤:

  • create an additional main method in a class which doesn't extend application and simply calls your real main method.在一个不扩展应用程序的类中创建一个额外的 main 方法,只是调用你真正的 main 方法。
  • include the .so files in the JAR.在 JAR 中包含.so文件。

To do that in IntelliJ, it's:要在 IntelliJ 中做到这一点,它是:

File > Project Structure > Artifacts > click the "+" symbol > File > and then select all the .so files in the JavaFX folder.文件 > 项目结构 > 工件 > 单击“+”符号 > 文件 > 然后选择 JavaFX 文件夹中的所有 .so 文件。

scenario:设想:

  1. you carefully follow "https://openjfx.io/openjfx-docs/#install-javafx", the "Non-modular with Maven"您仔细遵循“https://openjfx.io/openjfx-docs/#install-javafx”,即“非模块化 Maven”

  2. you app does run inside IntelliJ您的应用程序确实在 IntelliJ 中运行

  3. Yo cannot build a correct jar你不能构建一个正确的罐子

  4. You DON'T want to fight with你不想和

..EXPORT / .. --wtf .... : --module-path $PATH_TO_FX --add-modules ..EXPORT / .. --wtf .... : --module-path $PATH_TO_FX --add-modules

  1. due to a known problem, ( http://mail.openjdk.java.net/pipermail/openjfx-dev/2018-June/021977.html )由于已知问题,( http://mail.openjdk.java.net/pipermail/openjfx-dev/2018-June/021977.html

We have to use an helper class.我们必须使用辅助类。

  1. add the following class "Helper" and make it the "MAIN" class添加以下类“Helper”并使其成为“MAIN”类

    public class Launcher {公共类启动器{

     public static void main(String[] args) { App.main(args); }

    } }

  2. change refs in maven from you actual name (if starting from javafx site sample.. ) to this Launcher class:将 maven 中的 refs 从您的实际名称(如果从 javafx site sample.. 开始)更改为这个 Launcher 类:

from:从:

org.example.App org.example.App

to:到:

org.example.Launcher org.example.Launcher

  1. add SHADE plug in to manven:在 manven 中添加 SHADE 插件:

    org.apache.maven.plugins maven-shade-plugin 3.2.0 org.apache.maven.plugins maven-shade-plugin 3.2.0
     <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>project-classifier</shadedClassifierName> <outputFile>shade\\${project.artifactId}.jar</outputFile> <transformers> <transformer implementation= "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <!-- original: <mainClass>org.example.App</mainClass> --> <mainClass>org.example.Launcher</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin>
  2. to run in intelliJ, change main class in "Edit Configuration" to "Launcher"要在 IntelliJ 中运行,请将“编辑配置”中的主类更改为“启动器”

  3. ... run "mvn clean!" ...运行“mvn clean!” :) :)

PS: You can see ti in action here: PS:您可以在这里看到 ti 的运行情况:

https://github.com/ingconti/SampleJavaFxWithResize https://github.com/ingconti/SampleJavaFxWithResize

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

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