Update 58.2. Packaging executable jar and war files.md
parent
fd0ad3bf9d
commit
3d2e923dea
|
@ -0,0 +1,44 @@
|
||||||
|
### 58.2. 打包可执行jar和war文件
|
||||||
|
|
||||||
|
一旦`spring-boot-maven-plugin`被包含到你的pom.xml中,它就会自动尝试使用`spring-boot:repackage`目标重写存档以使它们能够执行。为了构建一个jar或war,你应该使用常规的packaging元素配置你的项目:
|
||||||
|
```xml
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<!-- ... -->
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<!-- ... -->
|
||||||
|
</project>
|
||||||
|
```
|
||||||
|
生成的存档在`package`阶段会被Spring Boot增强。你想启动的main类即可以通过指定一个配置选项,也可以通过为manifest添加一个`Main-Class`属性这种常规的方式实现。如果你没有指定一个main类,该插件会搜索带有`public static void main(String[] args)`方法的类。
|
||||||
|
|
||||||
|
为了构建和运行一个项目的artifact,你可以输入以下命令:
|
||||||
|
```shell
|
||||||
|
$ mvn package
|
||||||
|
$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar
|
||||||
|
```
|
||||||
|
为了构建一个即是可执行的,又能部署到一个外部容器的war文件,你需要标记内嵌容器依赖为"provided",例如:
|
||||||
|
```xml
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<!-- ... -->
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<!-- ... -->
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- ... -->
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
|
```
|
||||||
|
**注**:具体参考[“Section 74.1, “Create a deployable war file”” ](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-create-a-deployable-war-file)章节。
|
||||||
|
|
||||||
|
在[插件信息页面](http://docs.spring.io/spring-boot/docs/1.3.0.BUILD-SNAPSHOT/maven-plugin/)有高级的配置选项和示例。
|
Loading…
Reference in New Issue