Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java gradle没有为Spring boot生成War_Java_Spring_Spring Boot_Gradle - Fatal编程技术网

Java gradle没有为Spring boot生成War

Java gradle没有为Spring boot生成War,java,spring,spring-boot,gradle,Java,Spring,Spring Boot,Gradle,我有一个简单的spring启动应用程序,它作为独立应用程序运行。我开始使用在线指南转换为战争 buildscript { repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE") } } apply plugin: 'java' apply

我有一个简单的spring启动应用程序,它作为独立应用程序运行。我开始使用在线指南转换为战争

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

但没有战争产生。为什么?

战争可能是在你期望的地方产生的。添加到构建脚本中

logger.lifecycle "war.archivePath = $war.archivePath"

在我的例子中,使用
spring boot gradle插件:2.0.0。发布
gradle 4.2
,出于某种原因,
引导战
不是由
gradlew WAR
触发的。我刚刚执行了下面的命令,生成了war文件:

./gradlew bootWar

SpringBoot禁用war任务。只需在脚本中重新启用它。我不喜欢BootWar,它为传统的war部署创建lib提供的文件夹和其他org文件夹类

war {
    enabled= true
}

如何
gradlew build
。什么让你认为没有战争产生?你在哪里找的?输出显示war任务已执行,因此war应该位于
build/distributions/
。我在build\libs\knz-simulator-1.0.0.war中找到了一个war。这是目标war吗?构建包含以下目录:类、库、资源、tmp。顶层目录中没有目标或dist目录。具体取决于您如何配置
war
任务和项目。默认情况下,war插件添加的war-of-war任务应该在
build/distributions/
中,但可能是spring-boot重新配置了它。您可以在构建脚本中输出war的目标路径,以查看其生成位置。Simulator>gradlew build war.archivePath=Simulator\build\libs\Simulator-1.0.0.war。奇怪的路径。为什么你认为这是一条奇怪的路径,你会想到什么?我在寻找某个目标或dist目录。在我看来,Libs就像是在打包之前放置库的中间目录。正如我所说,由
war
插件添加的
war
任务的默认路径是
build/distributions/
。所以一定是什么改变了它。我猜它是spring启动插件,因为它与战争有关,以产生最终结果。但我不知道spring boot,所以我不知道。也许这会有帮助: