This is the 22nd day of my participation in the August More Text Challenge

If ❤️ my article is helpful, welcome to like, follow. This is the biggest encouragement for me to continue my technical creation. More previous articles in my personal column

Unable to execute jAR-file: “No master list properties” problem handling

scenario

Today, IN my spare time, I wrote the Java script to clean the ETL business data, and uploaded the JAR package to the server using the command Java -jar etlmembertag. jar to execute the error:

Can’t execute jar-file: “No main manifest attribute”

Unable to execute jar-file: “No master list properties”

To solve the problem, I looked up the Internet. And the solution to the problem is sorted out as follows

META-INF/MANIFEST.MF

To make the JAR package executable, you need to create a file called meta-INF/manifest.mf for the JAR

Meta-inf/manifest.mf is a MANIFEST file that exists in a JAR package file, The basic properties of meta-INF/manifest.mf in a JAR configuration file are as follows:

  • The Manifest – Version: definitionmanifestFor example:The Manifest - Version: 0.1
  • Created-By: specifies the generator of a file. This property is usually Created ByJar command line toolGenerate, for example: Created-By: Apache Ant 1.8.2
  • Signature-version: indicates the Signature Version
  • Class-path: indicates the dependency list. If there are multiple dependencies, separate them with Spaces. The dependency path is the relative path with the JAR package path as the reference frame.

Back to the question

The configuration file

We need to configure the meta-INF/manifest.mf file, but the file itself should have (at least) this line:

Main-Class: com.mypackage.MyClass
Copy the code

The com.mypackage.myClass position is the position of the class that you need to implement the entry point of public static void main(String[] args).

After the configuration is complete, you can repackage it to the CLI and run the following command:

jar cmvf META-INF/MANIFEST.MF .jar

maven pom.xml

For Maven, you can also use the following code content to solve the problem. Note that this is only the main class declaration, not the complete POM.xml:

The latest document this plug-in: please refer to the maven.apache.org/plugins/mav…

<build> <plugins> <plugin> <! -- Build an executable JAR --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.1.0</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>com.mypackage.MyClass</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build>Copy the code