Spring Boot打包war jar 部署tomcat
概述
1.spring boot聚合工程打包war部署tomcat
2.spring boot打包jar,通过java -jar直接运行.
3.提供完整pom.xml测试项目 至github
解决问题
1.xxxx中没有主清单属性
2.解决没有web.xml而报错
[error] failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project provider: error assembling war: webxml attribute is required(or pre-existing web-inf/web.xml if executing in update mode) -> [help 1]
版本
1.jdk 1.8
2.spring boot 1.5.8
3.apache-tomcat-8.5.23
一.
打包war部署tomcat
1.改写app类 继承springbootservletinitializer
2.重写configure方法,返回builder.sources(youapp.class);
3.添加pom.xml ,如下图
4.修改<packaging>war</packaging>
5.package命令打包
6.可参考 github--> releases--> v0.1 中blog-main-service 它是一个可打包jar且通过java -jar运行的完整项目配置
地址:https://github.com/mmdsyl/blog-microservice/releases
public class managerapplication extends springbootservletinitializer{ // for tomcat @override protected springapplicationbuilder configure(springapplicationbuilder builder) { return builder.sources(managerapplication.class); } public static void main(string[] args) throws interruptedexception { springapplication application = new springapplication(managerapplication.class); //application.setbannermode(banner.mode.off); application.run(args); } } <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-tomcat</artifactid> <scope>provided</scope> </dependency> <!--用于解决没有web.xml报错--> <plugin> <artifactid>maven-war-plugin</artifactid> <version>3.0.0</version> </plugin>
二.
打包jar执行运行
1.标准的application,不要继承springbootservletinitializer
2.修改pom,如图
3.package命令打包
4.可参考 github--> releases--> v0.1.1 中blog-main-web ,它是一个可打包war可部署tomcat中的完整配置
地址:https://github.com/mmdsyl/blog-microservice/releases
<!--打包成jar--> <!--https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html--> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>
总结
以上所述是小编给大家介绍的spring boot打包war jar 部署tomcat,希望对大家有所帮助