banner



How To Set Main Class In Manifest File

Every executable jar file in a Java application should contain a main method. Information technology is usually placed at the showtime of the awarding. Manifest files must be included with self-executing jars, also as existence wrapped in the projection at the appropriate location, to run a main method. Manifest files take a chief attribute that specifies the class having the master method.

"no main manifest attribute" is a mutual error which happens when we try to run an executable jar file. The full error output may wait like what's shown below

          Unable to execute jar- file: "no main manifest attribute."                  

Or

          no master manifest attribute, in target/exec.jar        

img

In this commodity, nosotros will prove you lot a few possible set that you tin apply to your Java project to avert getting "no chief manifest attribute" mistake.

Why "no main manifest attribute"?

"no main manifest attribute" fault bulletin is thrown because of various reasons, but near of the time, information technology fall under 1 of the following category.

  • Missing entry signal of Main-Class in MANIFEST.MF file.
  • Missing Maven dependency in pom.xml
  • Missing entry point in build.gradle

The Primary, or Main-Course is an essential attribute to make your jar executable. It tells Java which form would be used as the entry point of the application.

Without a Master, or Principal-Class aspect, Java have no way to know which grade it should run when yous execute the jar.

Inside the jar file, the MANIFEST.MF file is located in META-INF folder. Opening the jar file with WinRAR, you would see the contents of it, along with MANIFEST.MF.

A typical MANIFEST.MF file should contain the following lines

          Manifest-Version: the version of the Manifest file. Built-By: your PC proper name. Build-Jdk: the JDK version installed in your machine. Created-By: the plugin proper noun used in IDE.        

Beneath is an example of a MANIFEST.MF file.

Main-Class in MANIFEST.MF

Putting maven-jar-plugin in pom.xml

The "no primary manifest aspect" error message may occur in a Maven project due to the absence of the Main-Course entry in MANIFEST.MF.

This result can be resolved by adding maven-jar-plugin to our pom.xml file.

          <build>       <plugins>           <plugin>               <!-- Build an executable JAR -->               <groupId>org.apache.maven.plugins</groupId>               <artifactId>maven-jar-plugin</artifactId>               <version>3.ane.0</version>               <configuration>                   <annal>                       <manifest>                           <mainClass>com.linuxpip.AppMain</mainClass>                       </manifest>                   </annal>               </configuration>           </plugin>       </plugins>   </build>                  

In the lawmaking snippet higher up, com.linuxpip.AppMain is our fully-qualified proper noun of the Master-Class. You have to change this according to your specific project.

If you need more information, dig deep into maven-jar-plugin documentation: see https://maven.apache.org/plugins/maven-jar-plugin/

Specify Master-Course in Gradle

The following entries tin exist put into your build.gradle file if you receive this fault in your Gradle project:

          plugins {     id 'java' }  jar {     manifest {         attributes(                 'Main-Class': 'com.linuxpip.MyClass'         )     } }        

In the lawmaking snippet to a higher place, com.linuxpip.MyClass is our fully-qualified name of the Chief-Class. You accept to change this according to your specific project.

Change default MANIFEST.MF folder in IntelliJ IDEA

People have been reporting that IntelliJ Thought keeps putting the JAR antiquity into the wrong folder.

In club to fix "no main manifest attribute" in IntelliJ Thought, choose JAR > From modules with dependencies

From modules with dependencies

In the Create JAR from Modules window, modify the default Directory for META-INF/MANIFEST.MF path from <projection binder>\src\main\coffee to <project binder>\src\main\resources.

Otherwise it would generate the manifest and including it in the jar, but not the one in <project folder>\src\main\java that Coffee expects.

After that, just go on to Build Artifacts equally you usually practise.

IntelliJ IDEA Build Artifacts

Specify entry point in Eclipse

If you're exporting the JAR file in Eclipse, it has a congenital-in option that allows you to specify the Awarding'southward entry point, fugitive "no chief manifest attribute" error bulletin.

In Eclipse's JAR Consign window, you would see "Select the class of the application entry point" near the end of the Export process. Now you can pick a class and Eclipse will automatically generate the proper MANIFEST.MF file with the settings you've gear up.

Fix "no main manifest attribute" error message in Eclipse

Click to rate this post!

Source: https://linuxpip.org/fix-no-main-manifest-attribute/

0 Response to "How To Set Main Class In Manifest File"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel