spring - 在 Gradle 中使用 jettyRunWar 或 jettyRun 与 Spring Boot 应用程序只会在浏览器中列出一个目录

标签 spring gradle spring-boot

我是第一次使用 Gradle 和 Spring Boot。我决定创建一个实际构建 WAR 存档的项目,并且我正在使用 Gradle Jetty 插件。如果我运行 jettyRun 或 jettyRunWar 任务,在浏览器中我看到的只是目录列表,而不是我的实际应用程序。

例如,jettyRunWar 任务会生成如下目录列表:

META-INF/
WEB-INF/
dist/

dist/目录包含我的静态文件。

也许我错过了一些基本的东西,因为我是第一次使用 Gradle 和 Spring Boot。

我正在尝试测试我的应用程序,同时更改我的静态文件而不重新启动应用程序。这是我的 build.gradle 文件。

buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:0.5.0.M6"
    }
}

apply plugin: "java"
apply plugin: "idea"
apply plugin: "spring-boot"
apply plugin: "war"

war {
    baseName = "mis-support-client"
    version =  "1.0.0-SNAPSHOT"
    includes = ["dist/**"]
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-snapshot" }
}

dependencies {
    testCompile "junit:junit:4.11" 

    compile ("org.springframework.boot:spring-boot-starter-web:0.5.0.M7") {
        exclude module: "spring-boot-starter-tomcat"
    }
    compile "org.springframework.boot:spring-boot-starter-jetty:0.5.0.M7"
    compile "org.springframework.boot:spring-boot-starter-security:0.5.0.M7"
    compile "org.springframework.boot:spring-boot-starter-websocket:0.5.0.M7" 
    compile "javax.inject:javax.inject:1"
    compile "org.codehaus.jackson:jackson-mapper-asl:1.9.12"
    compile "org.apache.httpcomponents:httpclient:4.3.1"
    compile "commons-io:commons-io:2.4"
}

task wrapper (type: Wrapper) {
    gradleVersion = "1.8"
}

最佳答案

您是否尝试过./gradlew bootRun?普通的 Spring Boot 项目嵌入了服务器以方便使用:)

此任务需要 gradle 插件:

apply plugin: 'spring-boot'

功能

Embed Tomcat or Jetty directly (no need to deploy WAR files)

任务

Execution tasks
---------------
bootRun - Run the executable JAR/WAR

关于spring - 在 Gradle 中使用 jettyRunWar 或 jettyRun 与 Spring Boot 应用程序只会在浏览器中列出一个目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21029571/

相关文章:

java - Hibernate 读行锁定

java - 如何为 Spring、Android 和 Plain JAR 组织 Gradle?

java - 服务器端 URL 中的字符串参数解码错误

Spring Boot 卡住约 4 秒

Spring Security 由 : org. springframework.security.config.annotation.AlreadyBuiltException 引起:此对象已构建

java - Eclipse 上的 BuildShip Gradle 插件,报告 "syncrhonize gradle project workspace failed"

android - 在 gradle 文件中更新我的应用程序版本的问题

android - Android:在Ubuntu 16.04上运行应用程序时花费过多时间进行Gradle构建

angular - Spring云服务- Eureka

java - JPA 存储库和 Spring Security - 更新对象使密码无效