【问题标题】:Can't create war archive for spring-boot web project无法为 spring-boot web 项目创建战争档案
【发布时间】:2017-05-12 09:16:54
【问题描述】:

我已经通过 Intellij 创建了 spring-boot Web 项目,并且在通过 SpringApplication.run() 方法构建或启动项目后在任何地方都看不到我的 Web 存档。在文档页面上,我发现了三个应遵守的条款

  1. 生成可部署的 war 文件的第一步是提供 SpringBootServletInitializer
  2. 将战争插件应用到项目中
  3. 确保嵌入式 servlet 容器不会干扰将要部署 war 文件的 servlet 容器,方法是添加 providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' 构建脚本

我的 servlet 初始化器

public class ServletInitializer extends SpringBootServletInitializer {    
   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(RegTemplateApplication.class);
        }

    }

我的构建脚本

buildscript {
    ext {
        springBootVersion = '1.5.3.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('com.h2database:h2')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

【问题讨论】:

  • 我可以使用 IntelliJ 2016 和 Maven 创建一个 WAR。我现在没有代码在我面前。我会试着找到它。我没有看到我认为你需要的插件。你能在 Gradle 设置中突出显示它吗?
  • 我不确定 graille 但使用 maven 你可以运行 mvn package 并在 /target 文件夹中生成一个 WAR 文件
  • 运行应用程序当然不会引发战争。您必须在命令行(或在 IntelliJ 中)使用 gradle build 来创建工件。运行应用程序,顾名思义,就是运行应用程序。

标签: java spring-boot build.gradle


【解决方案1】:

要组装战争,你应该运行gradle assemble

默认情况下,此命令将从src/main/webapp 源创建战争工件。 还要检查您的来源是否在该目录中,或者您应该提供webAppDirName 属性

https://docs.gradle.org/current/userguide/war_plugin.html

【讨论】:

    【解决方案2】:

    我尝试使用:

    gradle clean build
    

    并在此目录中找到了网络存档:

    ./build/libs/build.war
    

    注意:你必须在你的机器上安装 gradle。

    【讨论】:

      猜你喜欢
      • 2018-07-05
      • 1970-01-01
      • 2020-02-26
      • 2019-01-10
      • 2013-03-08
      • 1970-01-01
      • 1970-01-01
      • 2019-03-23
      • 2017-04-12
      相关资源
      最近更新 更多