JavaFX打包:NoClassDefFoundError [英] JavaFX packaging: NoClassDefFoundError

查看:2624
本文介绍了JavaFX打包:NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用maven和OpenJDK打包JavaFX应用程序1.8
我的pom.xml中的相关部分:

I package a JavaFX application using maven and OpenJDK 1.8 The relevant part from my pom.xml:

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <archive>
                <manifest>
                    <addClasspath>true</addClasspath>
                    <mainClass>ui.Main</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
    </plugin>

现在重要的是以前的工作。我知道这是因为我特意做了一个git提交,其中包装最终起作用。
经过一天左右的时间以及这样的多个构建(我无法弄清楚改变了什么),由于以下错误,我无法再启动jar:

Now importantly this used to work. I know this because I specifically made a git commit where the packaging finally worked. After a day or so and multiple builds like this (I can't figure out what changed), I can no longer launch the jar because of the following error:

$ java -jar target/app.jar
Error: Could not find or load main class ui.Main Caused by:
java.lang.NoClassDefFoundError: javafx/application/Application

当我查看Jar的内容时,我可以看到所有依赖项都是特别包括,除了JavaFX类。

When I view the contents of the Jar, I can see that all dependencies are specifically included, except the JavaFX classes.

我尝试过:


  • 使用 javapackager构建jar

  • 使用javafx-maven-plugin修补

  • 在我的pom.xml中明确地添加JavaFX作为依赖项,希望程序集插件能为我打包它

以上都不是那是成功的。我能够启动我的应用程序的唯一方法是直接在IDE之外,这似乎意味着我的系统上仍然可以使用JavaFX库

None of the above was successful. The only way I'm able to launch my app is directly out of the IDE, which seems to mean that the JavaFX libs are still available on my system.

关于如何让它再次运行的任何想法?

Any ideas on how to get this to run (again)?

推荐答案

简短回答

我使用openJDK 11运行我的jar,而使用openJDK 8构建它时不包含JavaFX。案例已关闭。

I ran my jar with openJDK 11 while which does not include JavaFX while building it with openJDK 8. Case closed.

结果,详细信息和原因

由于我的IDE能够毫无问题地运行我的代码,我认为问题是特定于我的配置/机器。事实证明,Canonical / Ubuntu决定

Since my IDE was able to run my code without issues, I presumed the problem to be specific to my config/machine. As it turns out Canonical/Ubuntu decided


[For] Bionic [...] 移动默认的JRE / JDK 以2018年9月/ 10月的
作为SRU,以OpenJDK 11为主。 AskUbuntu

[For] Bionic [...] move the default JRE/JDK in main to OpenJDK 11 in September/October 2018 as an SRU. AskUbuntu

并且,正如在不同的SO线程上所指出的那样:

And, as pointed out on a different SO Thread:


JavaFX 11不再是JDK的一部分 StackOverflow

(这还包括说明如何使用JDK解决这个问题11)

(This also includes instructions how to fix this with JDK 11)

最后,正如Murpy的法律所规定的那样,我在10月4日设置了我的包装项目,并决定通过apt安装eclipse 10月8日,包括 openjdk-11-jdk:amd64 (这是记录在有用的 /var/log/apt/history.log )。

And finally, as Murpy's law had it, I set up my packaging the project on October 4th, and decided to install eclipse via apt on October 8th which includes openjdk-11-jdk:amd64 (this is logged in the useful /var/log/apt/history.log).

更新了我的 / etc / alternatives / java 指向v11。由于我在没有明确指定java二进制文件的情况下运行我的jar,它就破了。

This also updated my /etc/alternatives/java to point to v11. Since I ran my jar without explicitly specifying the java binary, it broke.

正在运行

/usr/lib/jvm/java-8-openjdk-amd64/bin/java -jar target/app.jar

快速测试按预期工作。现在我只需要将我的项目升级到openJDK 11,或者总是使用特定的JDK 8运行我的应用程序。

for a quick test works as expected. Now I only need to upgrade my project to openJDK 11 or else always run my app with the specific JDK 8.

这篇关于JavaFX打包:NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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