When executing Java – jar xxx.jar com.helloworld under Linux system, you will often be prompted: no main manifest attribute, in xxx.jar
The reasons are as follows:
Normally, when Java is packaged as a jar package, you need to specify the main class item in manifest.mf to find the corresponding main class when running Java – jar xxx.jar. Because – jar means that the following jar package has a main class to run independently, you need to specify this class when you package it into a jar package
If you want to specify the class you want to run at runtime, you should use – CP/– classpath to specify it. The command is as follows:
for example: Java – CP xxx.jar com.helloworld
Packaging can also be specified in the following way to directly run the jar file Java – jar XXX. Jar
<plugins>
<!-- When packaging the jar file, configure the manifest file and add the jar dependencies of the lib package -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<classesDirectory>target/classes/</classesDirectory>
<archive>
<manifest>
<mainClass>com.alibaba.dubbo.container.Main</mainClass>
<!-- Timestamped version not recorded in MANIFEST.MF file when packing -->
<useUniqueVersions>false</useUniqueVersions>
<addClasspath>true</addClasspath>
<classpathPrefix>crm-lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<type>jar</type>
<includeTypes>jar</includeTypes>
<outputDirectory>
${project.build.directory}/crm-lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Similar Posts:
- No main manifest attribute when running Java – jar
- no main manifest attribute, in demo-1.0.jar
- Maven no main manifest attribute when generate jar for project
- Maven warnning: ‘build.plugins.plugin.version’ is missing [How to Solve]
- Intellij Pack the jar file error: “java.lang.SecurityException: Invalid signature file digest for Manifest main attrib
- Remove dependency-reduced-pom.xml file when packaging Maven project
- [Solved] SpringBoot Package Error: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-res
- [Solved] Spring Boot Package Error: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0
- Unable to find a single main class from the following candidates [xxx,xxx]
- [Solved] SpringBoot Project Package to jar Error: ClassNotFound…