0

I have an OpenJFX Maven project. It successfully runs using Eclipse. When I create and run a jar(using java -jar app.jar) an error occurs: no main manifest attribute in jar.

The project dependencies and plugins from pom.xml:

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>14</maven.compiler.source>
        <maven.compiler.target>14</maven.compiler.target>
        <openjfx.version>14.0.2</openjfx.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${openjfx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>${openjfx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>${openjfx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${openjfx.version}</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>${openjfx.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <release>14</release>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <configuration>
                    <release>14</release>
                    <mainClass>top.jalva.tictactoe.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

I have tried to add maven-jar-plugin contains <manifest><mainClass>[path]</mainClass></manifest> but get this: Could not find or load main class [path] Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

Oleksii Valuiskyi
  • 2,691
  • 1
  • 8
  • 22
  • 1
    `NoClassDefFoundError` means that the class was available when the java code was compiled but it is not available when running the compiled code. This indicates that the runtime classpath is different to the compile-time classpath. The runtime classpath is determined by the `Class-Path` header in the `MANIFEST.MF` file in the JAR file or the command you use to launch your java application (or a combination of both). So [edit] your question and post the command you use to launch your app. – Abra Feb 25 '21 at 15:42
  • @Abra I launch the application from Windows console using `java -jar app.jar` without any arguments – Oleksii Valuiskyi Feb 25 '21 at 18:33
  • 1
    So you need to either change the [manifest](https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html) of the JAR file or change the [java command](https://docs.oracle.com/en/java/javase/11/tools/java.html#GUID-3B1CE181-CD30-4178-9602-230B800D4FAE) that you use to launch your application. – Abra Feb 26 '21 at 07:48

0 Answers0