edvin / fxlauncher

Auto updating launcher for JavaFX Applications
Apache License 2.0
713 stars 106 forks source link

Cannot run program "java" #141

Open joris-desmedt opened 5 years ago

joris-desmedt commented 5 years ago

When I run my native application (on windows without java in path) it start fxlauncher fine, but when fxlauncher tries to run my springboot jar I get this error.

java.io.IOException: Cannot run program "java": CreateProcess error=2, The system cannot find the file specified
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
    at java.base/java.lang.Runtime.exec(Runtime.java:635)
    at java.base/java.lang.Runtime.exec(Runtime.java:459)
    at java.base/java.lang.Runtime.exec(Runtime.java:356)
    at fxlauncher.Launcher.startApplication(Launcher.java:243)
    at fxlauncher.Launcher.lambda$launchAppFromManifest$2(Launcher.java:188)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.base/java.lang.ProcessImpl.create(Native Method)
    at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:420)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:151)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
    ... 14 more

Any idea what the reason for this is?

zuiailaoda commented 5 years ago

https://github.com/edvin/fxldemo/blob/master/pom.xml

joris-desmedt commented 5 years ago
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.6.RELEASE</version>
    <relativePath/>
  </parent>

  ...

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>10</java.version>

    <!-- Installer Filename without suffix -->
    <app.filename>appName</app.filename>

    <!-- The Application vendor used by javapackager -->
    <app.vendor>appVendor</app.vendor>

    <!-- Optional override to specify where the cached files are stored. Default is current working directory -->
    <app.cacheDir>./appName</app.cacheDir> <!-- since userlib doesn't work for springBoot -->

    <!-- The Application version used by javapackager -->
    <app.version>${project.version}</app.version>

    <!-- The Main class name -->
    <app.mainClass>org.springframework.boot.loader.JarLauncher</app.mainClass>

    <!-- The app and launcher will be assembled in this folder -->
    <app.dir>${project.build.directory}/app</app.dir>

    <!-- Native installers will be build in this folder -->
    <app.installerdir>${project.build.directory}/installer</app.installerdir>

    <!-- Base URL where you will host the application artifacts -->
    <app.url>...</app.url>

  </properties>

  <dependencies>
    <!-- Project dependencies -->

    ...

    <!-- fxlauncher dependencies-->
    <dependency>
      <groupId>no.tornado</groupId>
      <artifactId>fxlauncher</artifactId>
      <version>1.0.20</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-loader</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Compile project to appdir -->
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <outputDirectory>${app.dir}</outputDirectory>
        </configuration>
      </plugin>
      <!-- Copy dependencies to appdir -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.10</version>
        <configuration>
          <excludeScope>provided</excludeScope>
          <outputDirectory>${app.dir}</outputDirectory>
          <stripVersion>true</stripVersion>
          <includeGroupIds>no.tornado</includeGroupIds>
          <includeArtifactIds>fxlauncher</includeArtifactIds>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.4.0</version>
        <configuration>
          <includePluginDependencies>true</includePluginDependencies>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.4.0-b180830.0359</version>
          </dependency>
          <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.0</version>
          </dependency>
        </dependencies>
        <!-- Generate app.xml manifest -->
        <executions>
          <execution>
            <id>create-manifest</id>
            <phase>package</phase>
            <goals>
              <goal>java</goal>
            </goals>
            <configuration>
              <mainClass>fxlauncher.CreateManifest</mainClass>
              <arguments>
                <argument>${app.url}</argument>
                <argument>${app.mainClass}</argument>
                <argument>${app.dir}</argument>
                <argument>--cache-dir=${app.cacheDir}</argument>
                <argument>--include-extensions=jpg</argument>
              </arguments>
            </configuration>
          </execution>
          <!-- Embed app.xml inside fxlauncher.jar so we don't need to reference app.xml to start the app -->
          <execution>
            <id>embed-manifest-in-launcher</id>
            <phase>package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>jar</executable>
              <workingDirectory>${app.dir}</workingDirectory>
              <arguments>
                <argument>uf</argument>
                <argument>fxlauncher.jar</argument>
                <argument>app.xml</argument>
              </arguments>
            </configuration>
          </execution>
          <!-- Create native installer. -->
          <execution>
            <id>installer</id>
            <phase>install</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>javapackager</executable>

              <arguments>
                <argument>-deploy</argument>
                <argument>-native</argument>
                <argument>-outdir</argument>
                <argument>${app.installerdir}</argument>
                <argument>-outfile</argument>
                <argument>${app.filename}</argument>
                <argument>-srcdir</argument>
                <argument>${app.dir}</argument>
                <argument>-srcfiles</argument>
                <argument>fxlauncher.jar</argument>
                <argument>-appclass</argument>
                <argument>fxlauncher.Launcher</argument>
                <argument>-name</argument>
                <argument>${project.name}</argument>
                <argument>-title</argument>
                <argument>${project.name}</argument>
                <argument>-vendor</argument>
                <argument>${app.vendor}</argument>
                <argument>-BappVersion=${app.version}</argument>
                <argument>-Bidentifier=${project.groupId}.${project.artifactId}</argument>
                <argument>--add-modules</argument>
                <argument>java.xml.bind</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
joris-desmedt commented 5 years ago

In fxlauncher.Launcher.startApplication() Should getRuntime().exec(command) work if there is no jre in path? Wouldn't it be better to use java.net.URLClassLoader and invoke the main method?

edvin commented 5 years ago

That sounds reasonable to me, but I have never used spring boot and I don't know the reasoning behind doing it this way. Hopefully the author of that function will chime in :)