Search code examples
spring-bootmavenjavafxdesktop

Maven SpringBoot JavaFx app run on IDE not on command prompt


I am trying to build a JavaFX application using Spring Boot and maven, the app run perfectly on eclipse IDE, but not when i excute:

mvn spring-boot:run

the project is under JavaSE-17 (JDK 17.0.2), when i run the project from eclipse i add on VM argument of course:

--module-path C:\Users\piratack007\Desktop\javafx-sdk-19.0.2.1\lib --add-modules=javafx.controls,javafx.fxml

otherwise it display on Eclipse IDE:

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

Now when i execute the project from command prompt i've got

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

How can i add JavaFx components from command prompt and run this spring boot project?

Pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.4</version>
        <relativePath/> 
    </parent>
    <groupId>com.example</groupId>
    <artifactId>ProjectVetoBooksSpringBoot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>ProjectVetoBooksSpringBoot</name>
    <description>VetoBooks App V1.0.0</description>

    <properties>
        <java.version>17</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.19</version>
         </dependency>
         <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
             <dependency>
                 <groupId>org.apache.httpcomponents</groupId>
                 <artifactId>httpclient</artifactId>
             </dependency>
         
         <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-jdbc</artifactId>
        
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
       
        
        <!-- <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.28.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
           <artifactId>mysql-connector-java</artifactId>
           <version>8.0.16</version>
        </dependency>-->
        <dependency>
            <groupId>javax.json</groupId>
            <artifactId>javax.json-api</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.json</artifactId>
            <version>1.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.json/json -->
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160810</version>
        </dependency>
 
         
         <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-swing -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>13</version>
        </dependency>
         
         <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
        <dependency>
             <groupId>org.openjfx</groupId>
             <artifactId>javafx-controls</artifactId>
             <version>11.0.1</version>
        </dependency>
         <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-web -->
        <dependency>
             <groupId>org.openjfx</groupId>
             <artifactId>javafx-web</artifactId>
             <version>13</version>
        </dependency>
         <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-base -->
        <dependency>
             <groupId>org.openjfx</groupId>
             <artifactId>javafx-base</artifactId>
             <version>14.0.1</version>
        </dependency>
         <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>14</version>
        </dependency>
    </dependencies>

    <build>
    
        <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                </plugin>   
        </plugins>
        <!--<resources>
            <resource>
                <targetPath>/resources</targetPath>
                <directory>${basedir}/src/main/resources</directory>
            </resource>
         </resources>-->
        
    </build>
    <!--<profiles>
             <profile>
                      <id>default</id>
                      <activation>
                         <activeByDefault>true</activeByDefault>
                      </activation>
                      <properties>
                            <database.driverClassName>org.sqlite.JDBC</database.driverClassName>
                            <database.url>jdbc:sqlite:/resources/db/database2.sqlite</database.url>
                      </properties>
              </profile>
     </profiles>-->

</project>

Solution

  • Since Java 11, JavaFX was removed from the SDK. It is now in its own separate module, and if we want to use it in our application from cmd using mvn spring-boot:run without --module-path and --add-modules, we will need to use jdk that contain JavaFx from command line like zulu fx jdk, and it's done.