3

I have the problem that I just can't export my JavaFX application. I can get it running with the VM arguments (inside the IDE and outside) but that's far from optimal. I want a simple "click to open" experience.

Error: JavaFX runtime components are missing, and are required to run this application

I am aware that this problem can be fixed with the vm arguments but as I said before "click to open" experience.

I tried to make a fat jar using maven. (Here is my pom.xml):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Test</groupId>
  <artifactId>Test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
   <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>11</version>
        </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
  <plugins>
       <plugin>
           <artifactId>maven-assembly-plugin</artifactId>
           <version>3.1.1</version>
           <executions>
               <execution>
                   <id>make-jar-with-dependencies</id>
                   <phase>prepare-package</phase>
                   <goals>
                       <goal>single</goal>
                   </goals>
                   <configuration>
                       <archive>
                           <manifest>
                               <mainClass>test.Main</mainClass>
                           </manifest>
                       </archive>
                       <descriptorRefs>
                           <descriptorRef>jar-with-dependencies</descriptorRef>
                       </descriptorRefs>
                   </configuration>
               </execution>
           </executions>
       </plugin>
   </plugins>
 </build>
</project>

I still get the same error but the export process took way longer than usual probably because the JavaFX components were exported too. I think it is worth mentioning that I get a warning in my pom.xml

Overriding managed version 2.2-beta-5 for maven-assembly-plugin pom.xml

Here is my module-info.java (Maybe it helps solving the problem):

module Test {

    requires transitive javafx.controls;
    exports test;

}
  • 1
    With the new java module system, this will be very hard. The best that Oracle / OpenJDK came up with is a start script - a `*.bat` or `*.sh` file. It should be possible to create a shaded jar including all classes using the maven-shade-plugin and jlink to create a custom JRE including the required JavaFX modules. I also managed to create a launch4j executable using the launch4j-maven-plugin. There are many ways to get a click-to-open experience. It depends on what you actually want and to the way and the destination you want to deliver to. – Jochen Reinhardt Nov 19 '19 at 15:02
  • That’s really frustrating, why did they even come up with this... Thank you anyway! –  Nov 19 '19 at 17:08
  • No, not really. –  Nov 20 '19 at 07:11
  • I think you are missing the javafx-graphics dependency. For Windows, e.g.: ` org.openjfx javafx-graphics 11 win ` – Erik Nellessen Nov 21 '19 at 16:32

2 Answers2

0

As I understand the question, a JAR containing the JavaFX dependencies would be an answer.

Using e.g. Maven, it can be created like this:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.1</version>
            <executions>
                <execution>
                    <id>make-jar-with-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>my.group.id.myMain</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Depending on the target platform, you could also wrap the JAR into something using the correct JRE. The launch4j Maven plugins provides further possibilities for this direction.

Erik Nellessen
  • 402
  • 5
  • 9
0

Okay. After some fiddling around and some research I am glad to say that I finally found a solution. My problem with maven was that I compiled with eclipse and did not build with maven. So here is my final pom.xml for my project:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Project-Zola</groupId>
  <artifactId>Project-Zola</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics </artifactId>
        <version>11</version>
        <classifier>win</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>11</version>
        <classifier>linux</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics </artifactId>
        <version>11</version>
        <classifier>mac</classifier>
    </dependency>

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml </artifactId>
        <version>11</version>
        <classifier>win</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11</version>
        <classifier>linux</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml </artifactId>
        <version>11</version>
        <classifier>mac</classifier>
    </dependency>

  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>12</release>
        </configuration>
      </plugin>
      <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>exec-maven-plugin</artifactId>
         <version>1.6.0</version>
         <executions>
             <execution>
                 <goals>
                     <goal>java</goal>
                 </goals>
             </execution>
         </executions>
         <configuration>
             <mainClass>at.dominik.zola.main.Launcher</mainClass>
         </configuration>
     </plugin>
     <plugin>
         <artifactId>maven-jar-plugin</artifactId>
         <configuration>
             <archive>
                 <manifest>
                     <mainClass>
                         at.dominik.zola.main.Launcher
                     </mainClass>
                 </manifest>
             </archive>
         </configuration>
     </plugin>
     <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
         <version>3.2.0</version>
         <executions>
             <execution>
                 <phase>package</phase>
                 <goals>
                     <goal>shade</goal>
                 </goals>
                 <configuration>
                     <transformers>
                         <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                             <mainClass>at.dominik.zola.main.Launcher</mainClass>
                         </transformer>
                     </transformers>
                 </configuration>
             </execution>
         </executions>
     </plugin>
    </plugins>
  </build>
</project>

The jar is executable now and I have to give props to Erik Nellessen because he already submitted a similar answer. This pom.xml is also cross-platform compatible. But be careful if you are using the JavaFX web stuff you need to also include the JavaFX web components in the pom. I generally do not recommend that because the jar would then also include WebKit components and its size would increase by like 200mb. Thank's to all the people who tried to help me :)

NOTE: It is important that your main class does not extend the Application class that's why I created a Laucher class wich just calls the main method in the actual main class.