多模块springboot项目打jar包 没有主清单属性
说明:一个多模块的项目 两个子Module 一个core 一个server。java8的环境
| -- XChome (pom.xml xchome的 父级)
--|--xc-core (pom.xml xc-core的 子级)
--|--xc-server (pom.xml xc-server的 子级)
xc-core:主要定义一些常量类、工具类、业务部分(controller service dao)
xc-server: 只有一个主启动类和配置文件
xc-server的pom文件中引入了xc-core的maven坐标。
对xc-server打jar包。运行后发现 提示没有主清单属性。排查发现是因为jar包的MANIFEST.MF文件中没有主启动类,找了很多博客,都是说要替换maven plugin,试了很多也不行,另外,一些博客上说 打包插件要注明主启动类 <mainClass>xxxx.xxx.xxx.XXXApplication</mainClass> 完全没卵用。
父级的pom中没有任何打包相关的插件,build都没有。
xc-core模块中也没有任何打包相关的插件。
xc-server模块的pom中的打包插件如下:
<profiles>
<profile>
<id>package</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.4.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
注意使用springboot自带的maven插件一定要带上版本号。如果项目引入的springboot版本太高,默认的jdk是17,打包会遇到this version of the Java Runtime only recognizes class file versions up to 52.0
<!-- 或者使用2版本springboot maven插件 的 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>../dataroom-core/src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>

浙公网安备 33010602011771号