maven-compiler-plugin 与spring-boot-maven-plugin 打包
两种打包方式:
第一种:
maven打包,注意,这种打包方式不能用java -jar 启动。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
第二种:
1、 设置true会跳过主启动类,打包运行会提示没有主清单属性,服务启动失败;
2、maven的 实现把我们项目中 \lib 下自己使用的第三方lib打包。加true,代表maven打包时会将外部引入的jar包(比如在根目录下或resource文件下新加外部jar包)打包到项目jar,在服务器上项目才能运行,不加此配置,本地可以运行,因为本地可以再lib下找到外部包,但是服务器上jar中是没有的。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<mainClass>com.zjm.demo.DemoApplication</mainClass>
<!--<skip>true</skip>-->
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
建议第二种打包方式
如果是公共模块打包,作为其它引用使用,用第一种方式。
第二种打包方式也是基于maven打包,所以要设置maven的版本,否则打包会版本异常。
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
扩展:本地引入jar
<dependency>
<groupId>com.testjar.util</groupId>
<artifactId>test-sdk-for-web</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/sdk-for-web-1.0.7.jar</systemPath>
</dependency>