The jar packages generated by the MVN clean package are not executable by default because the information with the main method is not added to the manifest. When you run the package using Java-jar, the error is as follows:
No main manifest attribute, in Original-helloworld-1.0-snapshot.jar
In order to generate the executable jar package, it is necessary to build the executable jar package with the help of the Maven-shade-plugin plug-in, and other functions are available at the official website, the configuration example URL is:
Http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html
Configuration Code (Pom.xml):
<Project> ... <Build> <Plugins> <plugin> <groupId>Org.apache.maven.plugins</groupId> <Artifactid>Maven-shade-plugin</Artifactid> <version>2.3</version> <executions> <Execution> <Phase>Package</Phase> <Goals> <goal>Shade</goal> </Goals> <Configuration> <Transformers> <TransformerImplementation= "Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <MainClass>Org.sonatype.haven.HavenCli</MainClass> </Transformer> </Transformers> </Configuration> </Execution> </executions> </plugin> </Plugins> </Build> ...</Project
The key line is MainClass, which re-sets the entry address for the program to run, and the content is the class name we write.
Then rerun the MVN clean package to generate the executable jar, and when the package is executed again with the Java-jar command, the result is output normally.
Maven Package executable jar