The problem I have is that when I build a project and then tries to run the jar file nothing happens. When I run java -jar Tried-1.jar
I get this error message:
no main manifest attribute, in Tried-1.jar
I have open the jar file as an archive and found that the Main-Class:
line in the MANIFEST.MF
file doesn't exist. I have checked an older project that I built in Netbeans 12.0 and that one runs and has the Main-Class:
line in its Manifest file.
I tried to build the old project in Netbeans 12.2 and I encounter the same problem that the Main-Class:
line doesn't exist.
I have tried multiple fixes and none works, deciding what is the main class in project properties doesn't solve the problem, and other solutions to this problem by changing the pom.xml
file doesn't help either, just causes more problems.
I have also tried to run the class file within the jar file from the command prompt and that works fine.
I have read the documentation for Maven but I couldn't find anything to resolve my problem.
Update
I was able to fix the problem by chaning my pom.xml
file to this:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>Tried</artifactId>
<version>1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.tried.NewMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
But I still have the problem that I would need to add this every time I create a project, is there a way to make this automatic at every new project?
Netbeans 12.2 | Maven 3.6.3 | Java JDK 15.0.1