运行Java 11.02 JavaFX .jar应用程序会产生奇怪的输出

我一直在尝试创建和运行.jar文件,以便可以在运行Java运行时环境的任何计算机上运行JavaFX应用程序。

对于Java,我正在运行sdk版本11.02,对于JavaFX,我正在运行11.02 jdk。我的IDE是IntellJ IDEA。我确保已正确设置Windows环境变量,如下所示:

JAVA_HOME: C:\Program Files\Java\jdk-11.0.2

并在路径系统变量中:

c:\program files\java\jdk-11.0.2\bin
c:\program files\javafx-sdk-11.0.2\lib

在Intellj IDEA中,我已确保Path变量的设置如下:

运行Java 11.02 JavaFX .jar应用程序会产生奇怪的输出

我还确保我的项目使用的是正确的Java版本,并且正在使用javafx库:

运行Java 11.02 JavaFX .jar应用程序会产生奇怪的输出

运行Java 11.02 JavaFX .jar应用程序会产生奇怪的输出

我还确保应用程序运行器中的VM选项具有正确的命令:

运行Java 11.02 JavaFX .jar应用程序会产生奇怪的输出

这样,我可以通过IDE的内置应用程序运行器毫无问题地运行JavaFX程序。但是,如果我尝试创建一个jar文件并运行它,则不是这种情况。我尝试遵循this question的第一个答案的指南,即他谈论FAT Jar的部分。

我按照他的建议创建了一个Launcher类,与我的唯一不同是我需要添加一个throw异常子句,否则在.main部分上出现未处理的异常错误。

package main;

import com.sun.tools.javac.Main;

public class Launcher {
    public static void main(String[] args) throws Exception {
        Main.main(args);
    }
}

这是我最初的JavaFX入口点:

public class Main extends Application
{
    private ArmyBuilderRootPane view;

    @Override
    public void init()
    {
        Army model = new Army();
        view =  new ArmyBuilderRootPane(); 
        new ArmyBuilderController(view,model);     
    }

    @Override
    public void start(Stage stage)
    {
        stage.setTitle("Space Marine Army Builder");
        stage.setScene(new Scene(view));
        stage.show();
    }

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

然后我遵循他如何创建.jar文件的方法,首先在项目结构中设置工件,然后再构建它。当我尝试在内部IDE中并在外部Windows命令行中使用命令:java -jar SpaceMarineArmyBuilder.jar来运行此.jar时:得到以下输出:

"C:\Program Files\Java\jdk-11.0.2\bin\java.exe" --module-path "C:/Program Files/javafx-sdk-11.0.2/lib" --add-modules javafx.controls,javafx.fxml -Dfile.encoding=windows-1252 -jar "D:\Projects\Code\Space Marine Army Builder (7th Edition)\classes\artifacts\SpaceMarineArmyBuilder_jar\SpaceMarineArmyBuilder.jar"
Usage: javac <options> <source files>
where possible options include:
  @<filename>                  Read options and filenames from file
  -Akey[=value]                Options to pass to annotation processors
  --add-modules <module>(,<module>)*
        Root modules to resolve in addition to the initial modules,or all modules
        on the module path if <module> is ALL-MODULE-PATH.
  --boot-class-path <path>,-bootclasspath <path>
        Override location of bootstrap class files
  --class-path <path>,-classpath <path>,-cp <path>
        Specify where to find user class files and annotation processors
  -d <directory>               Specify where to place generated class files
  -deprecation
        Output source locations where deprecated APIs are used
  --enable-preview
        Enable preview language features. To be used in conjunction with either -source or --release.
  -encoding <encoding>         Specify character encoding used by source files
  -endorseddirs <dirs>         Override location of endorsed standards path
  -extdirs <dirs>              Override location of installed extensions
  -g                           Generate all debugging info
  -g:{lines,vars,source}       Generate only some debugging info
  -g:none                      Generate no debugging info
  -h <directory>
        Specify where to place generated native header files
  --help,-help,-?            Print this help message
  --help-extra,-X             Print help on extra options
  -implicit:{none,class}
        Specify whether or not to generate class files for implicitly referenced files
  -J<flag>                     Pass <flag> directly to the runtime system
  --limit-modules <module>(,<module>)*
        Limit the universe of observable modules
  --module <module-name>,-m <module-name>
        Compile only the specified module,check timestamps
  --module-path <path>,-p <path>
        Specify where to find application modules
  --module-source-path <module-source-path>
        Specify where to find input source files for multiple modules
  --module-version <version>
        Specify version of modules that are being compiled
  -nowarn                      Generate no warnings
  -parameters
        Generate metadata for reflection on method parameters
  -proc:{none,only}
        Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...]
        Names of the annotation processors to run; bypasses default discovery process
  --processor-module-path <path>
        Specify a module path where to find annotation processors
  --processor-path <path>,-processorpath <path>
        Specify where to find annotation processors
  -profile <profile>
        Check that API used is available in the specified profile
  --release <release>
        Compile for a specific VM version. Supported targets: 6,7,8,9,10,11
  -s <directory>               Specify where to place generated source files
  -source <release>
        Provide source compatibility with specified release
  --source-path <path>,-sourcepath <path>
        Specify where to find input source files
  --system <jdk>|none          Override location of system modules
  -target <release>            Generate class files for specific VM version
  --upgrade-module-path <path>
        Override location of upgradeable modules
  -verbose                     Output messages about what the compiler is doing
  --version,-version          Version information
  -Werror                      Terminate compilation if warnings occur


Process finished with exit code 2

我不知道为什么会产生这个输出。它应该正在运行我的JavaFX应用程序。

如果有人可以帮助我,我将不胜感激。

谢谢。

straybird9 回答:运行Java 11.02 JavaFX .jar应用程序会产生奇怪的输出

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3114884.html

大家都在问