Spring boot can package the project directly into an executable jar file by adding the Spring boot package plugin to the Maven Pom.xml
<build ; <plugins ; <plugin ; <groupid ; org.springframework.boot</; <artifactid ; Sprin G-boot-maven-plugin</artifactid ; </plugin ; </plugins , </build >
This jar file, spring boot embedded tomcat, because can directly through the Jar-jar jar file path, directly run the service, but at this time, if I have the demand, want to directly packaged into a war package, and then put myself in tomcat execution, then we can do this
The Spring boot project that http://blog.csdn.net/yingxiake/article/details/51245565 this side of the file, let me change it, then package it into a war package.
1. Modify the Pom.xml, change the packing from Jar to war, and add the Tomcat dependency, scope->provided indicate that if the package is required, inline Tomcat is automatically provided
2. Open DemoApplication, let him directly inherit Springbootservletinitializer, and rewrite the Configure method, which provides a configuration service similar to Web. xml
PackageCom.example.demo;ImportOrg.springframework.boot.SpringApplication;ImportOrg.springframework.boot.autoconfigure.SpringBootApplication;ImportOrg.springframework.boot.builder.SpringApplicationBuilder;ImportOrg.springframework.boot.context.web.SpringBootServletInitializer;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RestController;@SpringBootApplication@RestController Public class demoapplication extends springbootservletinitializer{ @Override protectedSpringapplicationbuilderConfigure(Springapplicationbuilder application) {returnApplication.sources (Demoapplication.class); }@RequestMapping(value = {"/",""}) PublicStringHelloboot(){return "Hello boot !!"; } Public Static void Main(string[] args) {Springapplication.run (demoapplication.class, args); }}
Well here we can just right-click Run as->maven build. Enter the package's command, directly into the war pack,
Hit the war package directly on the project target can be seen
At this point, you can throw the war paper into your Tomcat's WebApp directory and run Tomcat directly to start the service, and in the browser input Http://localhost:8080/demo
Test
In addition to the STS can be packaged with maven command-line tools, STS itself also provides a package of functions
For example, when packaged into an executable jar file, right-click on the project export->runnable jar files
Then next, select the output path, and the main function of the program run
If you want to pack a war, instead of changing it to the one required by the war above, then just click on the project right-Export->war file.
Then click Next, select the output path, and you can make a war package directly.
It is important to note that if you want to use the STS export to the war, your project needs to be a standard Web project.
OK, Introduction to here, if you want the address of the demo, download directly below
Https://github.com/liuxg2013/spring-boot-web-demo.git
Spring Boot packages The project into a war in the STS