Spring Boot打war包

作者: ef43ffb32440 | 来源:发表于2017-07-21 16:13 被阅读78次

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打包的配置:
Intellij Idea的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 see myproject-0.0.1-SNAPSHOT.jar. The file should be around 10 MB in size. If you want to peek inside, you can use jar 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.

5. 至此,将xxx-version.war部署到servlet container(比如Tomcat、Jetty)即可。

相关文章

网友评论

    本文标题:Spring Boot打war包

    本文链接:https://www.haomeiwen.com/subject/xysekxtx.html