可执行 Jar:无法加载 main(但 main 在 ANT xml 中)

Executable Jar: Could not load main (but main is in ANT xml)

当我通过终端 运行 我的 jar 文件时,我没有任何问题。然而,当我把它放在我客户的电脑上时,它给了我以下错误(当我通过终端尝试时:

Error: could not find or load main class base.Main.

Caused by: NoClassDefFoundErrors javafx/application/Application

通常我会假设 Main 不包括在内。但是,我也导出了 ANT XML(包括在下面)并且 base.Main 是我的主要位置。我也很困惑,因为我可以通过我机器上的终端 运行 可执行 jar,没有任何问题。

我正在使用 STS 中的 运行nable jar 导出功能。我试过多次导出。我试过更改导出设置(循环选项)。我已经验证我的客户有一个有效的 JDK,尽管我怀疑这会是问题所在。

*我花了两个小时来寻找答案。虽然我确定那里有类似的问题,但我还没有找到与我遇到的问题完全匹配的时间。如果您看过,请随时 post 它。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="create_run_jar" name="Create Runnable Jar for 
Project BLIS with Jar-in-Jar Loader">
<!--this file was created by Eclipse Runnable JAR file Export 
Wizard-->
<!--ANT 1.7 is required-->
<!--define folder properties-->
<property name="dir.buildfile" value="."/>
<property name="dir.workspace" value="${dir.buildfile}"/>
<property name="dir.jarfile" value="/Users/me/Documents"/>
<target name="create_run_jar">
    <jar destfile="${dir.jarfile}/BLIS.jar">
        <manifest>
            <attribute name="Main-Class"            
value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader"/>
            <attribute name="Rsrc-Main-Class" value="base.Main"/>
            <attribute name="Class-Path" value="."/>
            <attribute name="Rsrc-Class-Path" value="./ spring-jdbc-3.2.11.RELEASE.jar spring-jdbc-3.2.11.RELEASE.jar mysql-connector-java- 
8.0.13.jar joda-time-2.10.1.jar"/>
            </manifest>
            <zipfileset src="jar-in-jar-loader.zip"/>
            <fileset dir="${dir.workspace}/BLIS/bin"/>
        </jar>
    </target>
</project>

我知道期望 "just work" 是不现实的。问题是我不确定我在哪里搞砸了。是不是因为Main-Class是资源加载器而不是base.Main?我以前没有使用过这个出口商,但我假设它 "loads the resource" 在检查 main 是否存在之前。

如有任何帮助,我们将不胜感激。

这一定主要是由于 javafx.application.Application class 在客户端计算机的 class 路径中不可用,即使它在您的计算机中。

Oracle 默认包含 javafx,但 OpenJDK 没有。如果是OpenJDK,则需要单独安装openjfx

最好检查两台机器的 Java 版本并进行比较。

希望这能帮助您解决问题。