0

Here's my simple JavaFX app that I am able to build a native installer using jfx:native with Maven:

public class HelloWorld extends Application {
    public static void main(String... args){
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) throws Exception {
        System.out.println("Hello world!");
    }
}

The installer is being created when running that maven build.

  • What could be the possible reasons for issues that even running the exe file installed by the installer the Main class would not execute (in this case "Hello Word!" does not show up in the console as expected?
  • In what way the maven plugin below can be tweaked such that the installation of the native package will add the exe into the PATH?

Here's the section of the POM for JavaFX:

<plugin>
        <groupId>com.zenjava</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>8.7.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>native</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>com.mycompany.HelloWorld</mainClass>
          <nativeInstallers/>
        </configuration>
      </plugin>
quarks
  • 33,478
  • 73
  • 290
  • 513
  • Just to be sure: you are starting your executable from the console? Otherwise there should not even be a console. – hotzst Jan 09 '17 at 20:57
  • Yes, calling the exe from console, it runs but no output at all – quarks Jan 09 '17 at 20:59
  • It's not immediately obvious that the JVM's stdout will be the console from which you launched the exe under this scenario. If you open a simple window, e.g. `primaryStage.setScene(new Scene(new StackPane(),400,400));` and `primaryStage.show();`, do you see the window? – James_D Jan 09 '17 at 21:07
  • Hmmm... it did run. So it seems System.out.println is not working for JavaFX? Actually what I am trying to do a CLI (Command Line Interface) app so it is important that the command line works. – quarks Jan 09 '17 at 21:33
  • It's not clear what you're trying to do. JavaFX is a GUI toolkit. Why would you have a command line interface in a GUI application? – James_D Jan 09 '17 at 22:02
  • @James_D a lot of developers tend to "SysOut" for debuggin/development ;) – FibreFoX Jan 11 '17 at 17:54
  • @FibreFoX Sure, but what does debugging/development have to do with a self-contained application? That is used for deployment. Typically you would double-click an icon to launch that, and there wouldn't even be a console. Anything you need for debugging after deployment should be in a log file, not pumped out to a console... – James_D Jan 11 '17 at 17:56
  • @James_D I think the OP tried to make a full deployment-cycle :D just with "executable" as the test-subject instead of the jar-file itself. Like checking "does it really work". Lazy development sometimes improves learning ;) – FibreFoX Jan 11 '17 at 18:00

1 Answers1

0

Disclaimer: I'm the maintainer of the javafx-maven-plugin!

I assume you are using this maven-plugin on windows, as this is what I am expecting with your question.

First: you are required to NOT call the "native" bundle, because it is a special setup for running as maven-lifecycle. Please change the executions to this:

<executions>
    <execution>
        <!-- required before build-native -->
        <id>create-jfxjar</id>
        <phase>package</phase>
        <goals>
            <goal>build-jar</goal>
        </goals>
    </execution>
    <execution>
        <id>create-native</id>
        <phase>package</phase>
        <goals>
            <goal>build-native</goal>
        </goals>
    </execution>
</executions>

Secondly: the linked windows executable does NOT invoke javaw, nor java. That windows-executable is build as a GUI-application only, which means that calling the exe-file from CLI will NOT print ANYTHING on the command line.

I already made this answer some time ago: Write to console from a native javafx app created with Inno Setup and maven

after some further digging, there is something I found interesting: the generated EXE-file is a simple windows-executable, no cli-executable as seen in the launcher-source-code, that is the reason you dont see any console-output but having the result when pipelining into some file.

This means you are required to use your own pre-built exe-file, or just remove SysOuts.

Community
  • 1
  • 1
FibreFoX
  • 2,858
  • 1
  • 19
  • 41
  • What do you mean by "remove SysOuts"? – quarks Jan 10 '17 at 17:00
  • And yes if the we do > out.txt the output is there, somehow I think there should be a way to display the console finally – quarks Jan 10 '17 at 17:38
  • Also is there a way to make the installed application exe path of the System PATH? – quarks Jan 10 '17 at 17:38
  • You should not use `System.out.println()`, you should use a logger-framework instead of depending on CLI. To add your application to system-path, your are required to change the installer-script, see this two different postings on the project [post 1](https://github.com/javafx-maven-plugin/javafx-maven-plugin/issues/38) [post 2](https://github.com/javafx-maven-plugin/javafx-maven-plugin/issues/251#issuecomment-269086605) – FibreFoX Jan 10 '17 at 17:47