一般这个问题出现在maven打包安装项目的时候出现
mvn install \ mvn package
一般来说默认打包生成的jar是无法直接运行,因为main(主方法)不会被添加到 manifest中,即 /META-INF/MANIFEST.MF文件中。无法看到 Main-Class一行。
所以有两个方法:
1、直接在文件中添加main方法所在的类:
2、在pom.xml添加:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven_shade_plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.lingz.demo1.Demo1Application</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
其中,<mainClass>标签指定了主类的位置。