【发布时间】:2017-12-03 04:23:29
【问题描述】:
我有一个简单的 Spring Boot 应用程序,它作为独立应用程序运行。我开始使用在线指南转换为 WAR。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
bootRun {
addResources = true
}
war {
baseName = 'simulator'
version = '1.0.0'
}
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-freemarker")
compile group: 'org.freemarker', name: 'freemarker', version: '2.3.23'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
初始化器:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
组装:
c:\dev\projekty\Simulator>gradlew war
:compileJava
:processResources
:classes
:war
BUILD SUCCESSFUL
Total time: 3.96 secs
但是没有创造战争。为什么?
【问题讨论】:
-
gradlew build怎么样。 -
是什么让你认为没有创造战争?你在哪里找的?输出表明战争任务已执行,所以战争应该在
build/distributions/。 -
我在 build\libs\knz-simulator-1.0.0.war 中发现了一场战争。这是目标战吗?
-
Build 包含以下目录:classes、libs、resources、tmp。顶层目录中没有 target 或 dist 目录。
-
取决于您如何配置
war任务和项目。默认情况下,war插件添加的war任务的war应该在build/distributions/,但可能是spring boot重新配置了这个。你可以在你的构建脚本中输出war的目标路径,看看它是在哪里生成的。
标签: java spring spring-boot gradle