微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Gradle中使用带有Spring Boot应用程序的jettyRunWar或jettyRun只会导致浏览器中的目录列表

我第一次使用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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐