1

Buongiorno,

I have a Java Project with some extra dependencies and I wanted to let Maven handle it.

So I added all dependencies in the pom.xml and Updated the Project with Maven. In my Maven Dependencies I have every package I need to run the programm, however I cant run my project again because I get this error:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.base not found

Do I still have to add the modules in my VM Arguments (Run config) or are they not needed since they are added threw maven?

If I run it without any VM Arguments I get this:

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

Here is a Screenshot from the Maven Dependencies:

Maven Dependencies

EDIT: I am able to make the build work but If I want to run the created .JAR File it gives me this error:

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

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>kantinen_managementsystem</groupId>
  <artifactId>kantinen_managementsystem</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Test KMS Maven</name>
  <description>Test Maven Build</description>
  
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <maven.compiler.source>16</maven.compiler.source>
    <maven.compiler.target>16</maven.compiler.target>
        <java.version>16</java.version>
    </properties>  
  
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>images</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
    
  <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <archive>
            <manifest>
                <addClasspath>true</addClasspath>
              <mainClass>KMS.Main</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>    
    
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
            <archive>
            <manifest>
                <addClasspath>true</addClasspath>
            <mainClass>KMS.Main</mainClass>
            </manifest>
            </archive>
          <release>16</release>
        </configuration>
      </plugin>
      
    <plugin>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>0.0.6</version>
        <configuration>
            <mainClass>KMS.Main</mainClass>
        </configuration>
    </plugin>    
    
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
            <archive>
            <manifest>
                <addClasspath>true</addClasspath>
            <mainClass>KMS.Main</mainClass>
            </manifest>
            </archive>        
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin> 
      
    </plugins>
  </build>
  
  <dependencies>
    <dependency>                                                    <!-- PostgreSQL -->
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.2.20</version>
    </dependency>
    
    <dependency>                                                    <!-- AnimateFX -->
        <groupId>io.github.typhon0</groupId>
        <artifactId>AnimateFX</artifactId>
        <version>1.2.1</version>
    </dependency>
    
    <dependency>
        <groupId>de.jensd</groupId>
        <artifactId>fontawesomefx</artifactId>
        <version>8.2</version>
    </dependency>
    
    <dependency>                                                    <!-- JavaFX - Controls -->
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>16</version>
    </dependency>
    
    <dependency>                                                    <!-- JavaFX - Graphics -->
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>16</version>
    </dependency>
    
    <dependency>                                                    <!-- JavaFX - Base -->
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-base</artifactId>
        <version>16</version>
    </dependency>
    
    <dependency>                                                    <!-- JavaFX - FXML -->
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>16</version>
    </dependency>
    
    <dependency>                                                    <!-- JavaFX - Web -->
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-web</artifactId>
        <version>16</version>
    </dependency>
    

<dependency>                                                    <!-- JavaFX - Swing -->
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-swing</artifactId>
    <version>16</version>
</dependency>

<dependency>                                                    <!-- JavaFX - Media -->
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-media</artifactId>
    <version>16</version>
</dependency>
                                                              
yesIamFaded
  • 1,970
  • 2
  • 20
  • 45
  • Have a look at the official docs: https://openjfx.io/openjfx-docs/#maven You can either use the javafx plugin or you have to handle the module stuff manually. – mipa Jul 27 '21 at 12:27
  • @mipa So i looked into it, thanks. But I still have issues with running the project. It just doesnt find javafx modules even though I added javafx-maven-plugin like its said in the Docs. – yesIamFaded Jul 27 '21 at 12:41
  • 1
    How looks your pom.xml? – Reporter Jul 27 '21 at 13:48
  • Have you checked if these files `javafx-base-16.jar`and `javafx-base-16-win.jar` are valid? You can doing it by opening these files into a text editor. The content must be start with the letters PK – Reporter Jul 27 '21 at 13:51
  • Looks like you are trying to create a fat jar file for your application. The [openjfx documentation](https://openjfx.io/openjfx-docs/#maven) provides [sample project](https://github.com/openjfx/samples/blob/master/CommandLine/Non-modular/Maven/hellofx/pom.xml) for doing that, it makes use of the org.openjfx javafx-maven-plugin and the maven-shade-plugin. I'd advise trying to make the sample project work in your environment, then if you get that to work, applying the same principles used in the sample to your project to get your project to work as you wish. – jewelsea Jul 27 '21 at 22:33
  • You are currently using [jar-with-dependencies](https://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies) with the maven assembly plugin, yet the documentation for that goal notes: "Note that jar-with-dependencies provides only basic support for uber-jars. For more control, use the Maven Shade Plugin" – jewelsea Jul 27 '21 at 22:34
  • Note especially, in the sample project I linked previously, the comments: `` and the section has classifiers for the required target platforms: `win`, `linux`, `mac`. – jewelsea Jul 27 '21 at 22:39
  • @jewelsea I have tried the implementation - but I still have the problem that it cant find javafx components. Do I need to specify vm arguments? Wich line is important to make javafx work. – yesIamFaded Jul 28 '21 at 08:11
  • Okay so it kinda works but I cant start it from powershell.. always have that something is missing. How do u start the jar on windows or with maven? mvn clean javafx:run does not work or at least where do i put the projectname wich i want to run – yesIamFaded Jul 28 '21 at 09:14
  • "where do I put the project name which I want to run" -> The [project name is in the pom.xml file](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Minimal_POM). `mvn javafx:run` will run the application using the pom.xml in the current directory. If you want to [use a different pom.xml file](https://stackoverflow.com/questions/4023597/specify-pom-xml-in-mvn-command-and-mix-goals-of-other-project/4023629) you can do that using the `-f` option `mvn -f javafx:run`. – jewelsea Aug 02 '21 at 19:22

2 Answers2

0

Can you move the javafx files to a different location? eg c:/ Sometimes such errors can be related to the file location. Redefine after copying files. You can open a different project and try. My answer may be bad but I wanted to give an idea.

Alpovo
  • 1
  • 3
0

Here is the Problem explained - and also how to fix it:

The reason is that the Java runtime will check if the main class extends javafx.application.Application, and if that is the case, it strongly requires the javafx platform to be available as a module, and not as a jar for example.

To fix it you have to create a "normal" Main and link your FX Main in that, after that you have to pick the new Main in the pom.xml setup.

Working example: src/Main.java

public class Main {

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

src/HelloFX.java

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;
//import javafx.graphics;

public class HelloFX extends Application {

    @Override
    public void start(Stage stage) {
        String javaVersion = System.getProperty("java.version");
        String javafxVersion = System.getProperty("javafx.version");
        Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        Scene scene = new Scene(l, 640, 480);
        stage.setScene(scene);
        stage.show();
    }

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

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>HelloFX</groupId>
  <artifactId>HelloFX</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>10</release>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>Main</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>Main</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <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>
  </dependencies>
</project>

Credit: https://github.com/javafxports/openjdk-jfx/issues/236

yesIamFaded
  • 1,970
  • 2
  • 20
  • 45