1

I've been trying to create and run a .jar file that I can run my JavaFX application on any computer running the Java runtime enviroment.

For Java i'm running sdk version 11.02 and for JavaFX i'm running the 11.02 jdk. My IDE is IntellJ IDEA. I've made sure that my Windows enviroment variables have been set up correctly like so:

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

And in the Path System variables:

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

In Intellj IDEA I've made sure the Path variables have been set like so:

enter image description here

I've also made sure that my project is using the right Java version and that the javafx libraries are being used:

enter image description here

enter image description here

I've also made sure that VM options in the Application runner has the correct command:

enter image description here

With this I can run my JavaFX program with no problems through the IDE's built in Application runner. But this is not the case If I try to create a jar file and run that. I tried following a guide to the first answer of this question, namely the part where he talks about a FAT Jar.

I created a Launcher class as he suggested, with the only difference with mine being that I needed to add a throw exception clause else I got an unhandled exception error on the .main part.

package main;

import com.sun.tools.javac.Main;

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

And here is my original JavaFX entry point:

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);
    }
}

I then follow how he creates a .jar file by first setting up the Artifacts in the project structure, and then finally building it. When I try to run this .jar in both the internal IDE and using the command: java -jar SpaceMarineArmyBuilder.jar within an external Windows command line: I get the following output:

"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

I have no idea why it's producing this output. It should be running my JavaFX application.

If anybody could help me i'd appreciate it.

Thanks.

SneakyShrike
  • 723
  • 1
  • 10
  • 31
  • Are you sure you run `java` and not `javac`? Might be some JDK corruption, try to reinstall it. – CrazyCoder Nov 12 '19 at 19:24
  • @CrazyCoder Well I'm sure I write java -jar SpaceMarineArmyBuilder.jar as the command when running in an external Windows CMD. And do you mean to reinstall the Java JDK or JavaFX? If so, would it be worth upgrading to version 13 on both? Thanks. – SneakyShrike Nov 12 '19 at 20:08

0 Answers0