首页 > 代码库 > Spring Boot 构建 WAR和JAR 文件
Spring Boot 构建 WAR和JAR 文件
原文:https://github.com/x113773/testall/issues/3
## JAR文件
方式一:
1. 修改[pom.xml](https://github.com/x113773/testall/blob/master/pom.xml)文件,添加maven插件
```
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
```
2. pom.xml所在目录执行maven命令: `mvn package`,或者MyEclipse —>右键项目—>Run As—>Maven build—>Goals里面填package,执行Run
方式二:
MyEclipse —>右键项目—>Run As—>Maven build—>Goals里面填
`org.apache.maven.plugins:maven-jar-plugin:2.4:jar org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage`
,执行Run
## WAR文件
1. 修改[pom.xml](https://github.com/x113773/testall/blob/master/pom.xml)文件,指定打包方式为war,排除内置Tomcat
`<packaging>war</packaging>`
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
```
2. 启动类[Application.java](https://github.com/x113773/testall/blob/master/src/main/java/com/ansel/testall/Application.java)继承SpringBootServletInitializer,覆盖configure()方法来指定Spring配置类。
```
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
```
3. pom.xml所在目录执行maven命令: `mvn package`,或者MyEclipse —>右键项目—>Run As—>Maven build—>Goals里面填package,执行Run
**jar文件和war文件都会生成在项目的target目录**
Spring Boot 构建 WAR和JAR 文件