spring-boot-maven-plugin
插件默认打的是jar包,如果需要打war包,需要以下的步骤:
1. 在build-plugins中加入maven-compiler-plugin
,配置编译使用的java版本:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
2. 在<dependencies>之前声明打war的包:
<packaging>war</packaging>
3. Intellij Idea的Edit Configuration,新建一个maven打包的配置:

4. 打包成功之后,在target目录下生成两个war包,一个是xxx-version.war,另一个是xxx-version.original.war。以下是Spring boot参考文档的原话,也即original包是maven插件打的原始的包,较小,而另一个包是spring boot repackage之后的包,较大。我们最终使用的是repackage的xxx-version.war的包,而不是original的包:
If you look in the
target
directory you should seemyproject-0.0.1-SNAPSHOT.jar
. The file should be around 10 MB in size. If you want to peek inside, you can usejar tvf
:
$ jar tvf target/myproject-0.0.1-SNAPSHOT.jar
You should also see a much smaller file named myproject-0.0.1-SNAPSHOT.jar.original
in the target
directory. This is the original jar file that Maven created before it was repackaged by Spring Boot.
网友评论