正在为 spring 引导应用程序生成 war
Generating war for spring boot application
我一直在学习 spring 提供的教程,但似乎无法理解为什么我的 .war 文件是空的。单击 here 以 see/download 代码。最终目标是下载此文件,构建一个 .war 文件,然后将其部署到我的 tomcat 服务器。我已将以下内容添加到 build.gradle
应用插件:"war"
但这只会生成包含零个 class 个文件的 war。
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle
plugin:1.5.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
// tag::tests[]
testCompile("org.springframework.boot:spring-boot-starter-test")
// end::tests[]
}
对于教程代码,您需要做两件事:
war 打包插件 spring-boot ref:
apply plugin: 'war'
war {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
创建可部署的 war 文件 spring-boot ref:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
并指定 tomcat 所提供的依赖项:
dependencies {
// …
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
// …
}
这是我的 commit reference 和结果:
我一直在学习 spring 提供的教程,但似乎无法理解为什么我的 .war 文件是空的。单击 here 以 see/download 代码。最终目标是下载此文件,构建一个 .war 文件,然后将其部署到我的 tomcat 服务器。我已将以下内容添加到 build.gradle
应用插件:"war"
但这只会生成包含零个 class 个文件的 war。
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle
plugin:1.5.3.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
// end::actuator[]
// tag::tests[]
testCompile("org.springframework.boot:spring-boot-starter-test")
// end::tests[]
}
对于教程代码,您需要做两件事:
war 打包插件 spring-boot ref:
apply plugin: 'war' war { baseName = 'gs-spring-boot' version = '0.1.0' }
创建可部署的 war 文件 spring-boot ref:
@SpringBootApplication public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); }
并指定 tomcat 所提供的依赖项:
dependencies {
// …
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
// …
}
这是我的 commit reference 和结果: