1

所以我第一次玩了spring boot,它运行得很好,除了我不知道如何构建一个.war文件来部署到我的个人服务器上。我已经阅读了 Spring 网站上的十几个或更多博客文档,但我就是不知道如何构建 .war。

我正在使用 intellij、kotlin 和 gradle。任何为我指明正确方向的帮助将不胜感激。

这是我的 gradle 文件的样子:

import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootJar
import org.springframework.boot.gradle.tasks.bundling.BootWar

plugins {
    kotlin("plugin.jpa") version "1.2.71"
    id("org.springframework.boot") version "2.1.6.RELEASE" 
    id("io.spring.dependency-management") version "1.0.7.RELEASE"
    kotlin("jvm") version "1.2.71"
    kotlin("plugin.spring") version "1.2.71"

    war


}

apply(plugin = "io.spring.dependency-management")

the<DependencyManagementExtension>().apply {
    imports {
        mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
    }
}



. . . .

dependencies {
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-mustache")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    runtimeOnly("com.h2database:h2")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.getByName<Jar>("jar") {
    enabled = true
}

tasks.getByName<War>("war") {
    enabled = true
}

tasks.getByName<BootJar>("bootJar") {
    classifier = "boot"
    mainClassName = "com.daniel.we_adventurers"
    launchScript()

    manifest {
        attributes("Start-Class" to "com.daniel.we_adventurersn")
    }
}



tasks.getByName<BootWar>("bootWar") {
    classifier = "boot2"
    mainClassName = "com.daniel.we_adventurers"
    launchScript()

    manifest {
        attributes("Start-Class" to "com.daniel.we_adventurers")
        attributes("Main-Class" to "org.springframework.boot.loader.PropertiesLauncher")
    }

}


}
4

2 回答 2

2

假设您已经使用https://start.spring.io/创建了项目,那么只需按照文档创建war存档:

https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#packaging-executable-wars

如果您没有使用https://start.spring.io/创建它,那么我建议从那里创建一个并将其用作更新当前项目的参考。

于 2019-06-21T02:08:30.423 回答
0

我知道你问已经有一段时间了,而且,因为我遇到了你的问题,我想说你的问题很可能与这条线有关:

developmentOnly("org.springframework.boot:spring-boot-devtools")

请在此处查看我对其他问题的回答Spring Boot Application Deployment Issue

它应该引导你朝着正确的方向前进。

于 2020-05-12T19:15:16.217 回答