0

I'm using the current NetBeans, and have just created a simple JavaFX project with the Maven compiler.

It runs, cleans, builds etc. perfectly fine, no errors, when in NetBeans.

However, when I navigate to the folder "...Documents\NetBeansProjects\Simple Banking Application\target" and run the executable Jar file, nothing happens. So I tried to run it manually via command line (Java -jar file.jar) it shows me the reason is because of an error:

No main manifest attribute

After searching, I found a supposed solution, involving adding these few lines to the POM.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <archive>
            <manifest>
            <addClasspath>true</addClasspath>
            <mainClass>com.mycompany.mavenproject2.App</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

Unfortunately, that just causes a new error:

Error: Could not find or load main class com.mycompany.mavenproject2.App Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

I'm at a loss, and I'm wondering if I'm just missing something obvious. A couple of preliminary notes: -I made sure to set this as my main project in NB -I'm using default configuration -I've tried cleaning and building, and just building as well, everything runs without any errors in NB -I've not modified anything settings-wises -I did refactor the project from mavenproject2 to Simple Banking Application, but I did so using NB's renaming options so that it does so 'safely'. (For the artifactID I had to remove the whitespaces) -I've made sure all the .class files and .java files are in the project folder (.java are found in src, .class are found in target>classes)

Just in case, here is my entire POM.xml document:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>SimpleBankingApplication</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>13</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.mycompany.mavenproject2.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>com.mycompany.mavenproject2.App</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                    </execution>
                    <execution>
                        <!-- Configuration for manual attach debugging -->
                        <!-- Usage: mvn clean javafx:run@debug -->
                        <id>debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Configuration for automatic IDE debugging -->
                        <id>ide-debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Configuration for automatic IDE profiling -->
                        <id>ide-profile</id>
                        <configuration>
                            <options>
                <option>${profiler.jvmargs.arg1}</option>
                <option>${profiler.jvmargs.arg2}</option>
                <option>${profiler.jvmargs.arg3}</option>
                <option>${profiler.jvmargs.arg4}</option>
                <option>${profiler.jvmargs.arg5}</option>
                            </options>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <name>Simple Banking Application</name>
</project>
0

1 Answer 1

2

You don't have the JavaFX components on your module path.

You can use a JDK which includes JavaFX (e.g. Azul JDK FX or Liberica Full JDK).

OR, you can follow the instructions below.

See the section on setting the VM arguments for running a JavaFX application as a jar file.

java --module-path /path/to/javafx-sdk-14/lib --add-modules javafx.controls,javafx.fxml -jar myJar.jar

You are using netbeans + maven, so refer to the official documentation openjfx.io JavaFX and NetBeans: modular with maven for more information. It discusses VM arguments for the Java module system to support JavaFX as well as creating runtime images using jlink.

If you don't know or understand the basics of the Java module system, then you should take some time to study and learn it from an appropriate tutorial. That will help you better understand the command line arguments required for the module system as well as the module-info.java alternative.

See the packaging instructions in the JavaFX tag which provide information on packaging alternatives (e.g. jlink and jpackage).

Use up-to-date software (e.g. JDK/JavaFX 18 and the maven-jar-plugin 0.0.8).

Don't use the maven-jar-plugin addClasspath option to build your jar when you have JavaFX component dependencies. The JavaFX components are not designed to be run from the classpath.

Sign up to request clarification or add additional context in comments.

7 Comments

I tried to use the VM command, and it came up with an error: "One of Run/Debug/Profile Project actions has been modified and the Run panel cannot be safely edited" I went in and reset some of the Actions in the action panel of properties, which allowed me to put VM arguments. However, the jar file still didn't exec, and this time instead of running normally in NetBeans, run came up with "Error: Could not find or load main class java Caused by: java.lang.ClassNotFoundException: java Command execution failed." I couldn't get NB to use the JavaFX version I downloaded, even with instructions
More info: it kept wanting to use the JavaFX 13 in its dependencies, and when I tried to get it to use a JavaFX SDK from Gluon like recommended, it wouldn't accept it as a platform. (I also couldn't find a way to add the JavaFX libraries to the project after first adding them to Tools->Libraries)
This indicates that your command line execution is incorrect. If you go a command line and type java java it will produce the exact same error text. So you have an extra java in the command line execution, it is treating the name java as the name of the class with the main() method in it, rather than your application class. I couldn't tell you why you have that other than that your runtime execution setup is incorrect and not generating the correct execution command.
On your not being able to use a version of JavaFX different from 13, that is just weird. NetBeans is not my primary development platform (I use Idea), so I can't really help you troubleshoot other than to point to the official documentation and advise that you are using the latest stable versions of all things (JDK/JavaFX/Maven/maven-javafx-plugin/etc), and especially the latest stable version of NetBeans.
Even then I believe there are some functions in NetBeans which are JavaFX specific but were created for JavaFX 8 and not for modular post JavaFX 11 builds, so you need to avoid using those features.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.