From dbce813b5ce4d27a53dae34395db2313e940790d Mon Sep 17 00:00:00 2001 From: qibaoguang Date: Tue, 10 Mar 2015 21:59:38 +0800 Subject: [PATCH] Update 59.4. Packaging executable jar and war files.md --- ... Packaging executable jar and war files.md | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/VIII. Build tool plugins/59.4. Packaging executable jar and war files.md b/VIII. Build tool plugins/59.4. Packaging executable jar and war files.md index e69de29..08554bd 100644 --- a/VIII. Build tool plugins/59.4. Packaging executable jar and war files.md +++ b/VIII. Build tool plugins/59.4. Packaging executable jar and war files.md @@ -0,0 +1,37 @@ +### 59.4. 打包可执行jar和war文件 + +一旦`spring-boot`插件被应用到你的项目,它将使用`bootRepackage`任务自动尝试重写存档以使它们能够执行。为了构建一个jar或war,你需要按通常的方式配置项目。 + +你想启动的main类既可以通过一个配置选项指定,也可以通过向manifest添加一个`Main-Class`属性。如果你没有指定main类,该插件会搜索带有`public static void main(String[] args)`方法的类。 + +为了构建和运行一个项目artifact,你可以输入以下内容: +```shell +$ gradle build +$ java -jar build/libs/mymodule-0.0.1-SNAPSHOT.jar +``` +为了构建一个即能执行也可以部署到外部容器的war包,你需要将内嵌容器依赖标记为"providedRuntime",比如: +```gradle +... +apply plugin: 'war' + +war { + baseName = 'myapp' + version = '0.5.0' +} + +repositories { + jcenter() + maven { url "http://repo.spring.io/libs-snapshot" } +} + +configurations { + providedRuntime +} + +dependencies { + compile("org.springframework.boot:spring-boot-starter-web") + providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") + ... +} +``` +**注**:具体参考[“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)。