无法为spring-boot Web项目创建war存档

时间:2022-03-24 23:25:07

I have created spring-boot web project by Intellij and can't see my web archive anywhere after build or start project by SpringApplication.run() method. On the documentation page I found three clauses that should be observed

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

  1. The first step in producing a deployable war file is to provide a SpringBootServletInitializer
  2. 生成可部署war文件的第一步是提供SpringBootServletInitializer

  3. Apply the war plugin to the project
  4. 将war插件应用于项目

  5. Ensure that the embedded servlet container doesn’t interfere with the servlet container to which the war file will be deployed by adding providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' to build script
  6. 通过添加providedRuntime'org.springframework.boot:spring-boot-starter-tomcat'来构建脚本,确保嵌入式servlet容器不会干扰war文件将部署到的servlet容器

My servlet initializer

我的servlet初始化程序

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

    }

My build script

我的构建脚本

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')
}

2 个解决方案

#1


2  

To assemble war you should run gradle assemble

要组装战争你应该运行gradle汇编

This command will create war artifact from src/main/webapp sources by default. Also check out that your sources are in that dir or you should provide webAppDirName property

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

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

#2


0  

I have tried to build using:

我试图建立使用:

gradle clean build

and found the web archive in this directory:

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

./build/libs/build.war

Note: you have to install gradle on your machine.

注意:您必须在计算机上安装gradle。

#1


2  

To assemble war you should run gradle assemble

要组装战争你应该运行gradle汇编

This command will create war artifact from src/main/webapp sources by default. Also check out that your sources are in that dir or you should provide webAppDirName property

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

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

#2


0  

I have tried to build using:

我试图建立使用:

gradle clean build

and found the web archive in this directory:

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

./build/libs/build.war

Note: you have to install gradle on your machine.

注意:您必须在计算机上安装gradle。