Issue
I have a java program I've just followed a tutorial and the .jar was created with Maven in Apache Netbeans 11. But the .jar doesn't execute... nothing happens. I even have a .bat file to run it but it says:Windows can't find file NewMain which is the main class.
<?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>mavenproject3</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency> <groupId>com.apple</groupId> <artifactId>AppleJavaExtensions</artifactId> <version>1.4</version> </dependency>
</dependencies>
<build>
<finalName>mavenproject3</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>com.mycompany</groupId>
<artifactId>mavenproject3</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
//Versión de JDK con la cual se ha construido el proyecto
// 1.8 significa que se utilizó Java8
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
//Sufijo que se le agregara al fichero JAR ejecutable
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
//Aqui se establece el nombre de la clase principal
<mainClass>com.MainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Is there something missing or something misplaced?
Manifest.mf
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: Usuario
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_231
Main-Class: MainClass
MainClass is not the main class
Update:
I've made the change
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: Usuario
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_231
Main-Class: NewMain
Now: NewMain parent class not found or loaded
Solution
Jar file should have Main-Class: name of the class containing the main (with package name)
parameter defined in Manifest.mf
.
Answered By - Rahul Chauhan
Answer Checked By - David Marino (JavaFixing Volunteer)