在运行使用maven打包的项目之后,运行项目发现主类没有找到。提示XXX–1.0-SNAPSHOT.jar中没有主清单属性
问题原因
maven在打包时没有配置主类。
解决方案
如果您使用的是Springboot框架,那么只需要在pom.xml中添加如下配置,会自动检测主类。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
如果你是其他项目,你需要手动定位到主类
<build>
<finalName>ddns</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<!--这里写你的main函数所在的类的路径名,也就是Class.forName的那个字符串-->
<mainClass>com.nw.DDNS</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>