0

I am trying to build my project to a runnable jar in intellij IDEA; I am using javaFx for the GUI. I have successfully run/built the project multiple times through development but now I have created an artifact as followed in another stackoverflow post and this didn't include the javafx dependency even though I selected it to and it's in the build path, My message is:Error: JavaFX runtime components are missing, and are required to run this application even though I have added the dependencies in build and to the environment variables. Is there a solution?

Thanks

2 Answers2

0

I had the same error message when trying to run a JAR file created with JavaFX 11 in IntelliJ.

You're just missing two additional steps:

  • create an additional main method in a class which doesn't extend application and simply calls your real main method.
  • include the .so files in the JAR.

To do that in IntelliJ, it's:

File > Project Structure > Artifacts > click the "+" symbol > File > and then select all the .so files in the JavaFX folder.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

scenario:

  1. you carefully follow "https://openjfx.io/openjfx-docs/#install-javafx", the "Non-modular with Maven"

  2. you app does run inside IntelliJ

  3. Yo cannot build a correct jar

  4. You DON'T want to fight with

..EXPORT / .. --wtf .... : --module-path $PATH_TO_FX --add-modules

  1. due to a known problem, (http://mail.openjdk.java.net/pipermail/openjfx-dev/2018-June/021977.html)

We have to use an helper class.

  1. add the following class "Helper" and make it the "MAIN" class

    public class Launcher {

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

    }

  2. change refs in maven from you actual name (if starting from javafx site sample.. ) to this Launcher class:

from:

org.example.App

to:

org.example.Launcher

  1. add SHADE plug in to manven:

    org.apache.maven.plugins maven-shade-plugin 3.2.0
         <executions>
             <execution>
                 <phase>package</phase>
                 <goals>
                     <goal>shade</goal>
                 </goals>
                 <configuration>
                     <shadedArtifactAttached>true</shadedArtifactAttached>
                     <shadedClassifierName>project-classifier</shadedClassifierName>
                     <outputFile>shade\${project.artifactId}.jar</outputFile>
                     <transformers>
                         <transformer implementation=
                                              "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
    
                             <!-- original:
                             <mainClass>org.example.App</mainClass>
                              -->
    
                             <mainClass>org.example.Launcher</mainClass>
    
                         </transformer>
                     </transformers>
                 </configuration>
             </execution>
         </executions>
     </plugin>
    
  2. to run in intelliJ, change main class in "Edit Configuration" to "Launcher"

  3. ... run "mvn clean!" :)

PS: You can see ti in action here:

https://github.com/ingconti/SampleJavaFxWithResize

ingconti
  • 10,876
  • 3
  • 61
  • 48