web-applications - 如何在 gradle 中设置 webAppDirName

标签 web-applications gradle build.gradle

How to change webAppDir to point to /web instead of src/main/webapp

我正在尝试将 webAppDir 更改为 WebContent(eclipse 中的动态 Web 应用程序结构)。

我正在使用 gradle 1.7。
当我尝试做与论坛中提到的相同的事情时,它给了我错误:

Creating properties on demand (a.k.a. dynamic properties) has been deprecated
and is scheduled to be removed in Gradle 2.0. 
Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html
for information on the replacement for dynamic properties.

Deprecated dynamic property: "webAppDirName" on "root project 'xxxxxxxxxx", value: "WebContent".

输出 WAR 包含两个文件夹“WEB-INF”和“META-INF”

更新
build.gradle
    webAppDirName='WebContent' 
apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'eclipse-wtp'

sourceSets {
    main {
        java {
            srcDir 'src'
        }
        resources {
            srcDir 'src'
        }

    }
}
configurations { moreLibs }

repositories {
    flatDir { dirs "WebContent/WEB-INF/lib" }
    mavenCentral()
}

dependencies {
    compile fileTree(dir: "WebContent/WEB-INF/lib", include: '*.jar')
    providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
    runtime 'javax.servlet:jstl:1.2'
}


/* Change context path (base url). otherwise defaults to name of project */
jettyRunWar.contextPath = ''

请帮忙。

另一个问题:

WEB-INF 文件夹也在 WebContent 下。 WebContent 的副本是否替换 classes 文件夹。

最佳答案

终于解决了。

答案是project.webAppDirName = 'WebContent'
Build.gradle 文件:

apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'eclipse-wtp'



project.webAppDirName = 'WebContent'

sourceSets {
    main {
        java { srcDir 'src' }
        resources { srcDir 'src' }
    }
}
configurations { moreLibs }

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: "WebContent/WEB-INF/lib", include: '*.jar')
    providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
    runtime 'javax.servlet:jstl:1.2'
}

war {
    exclude 'WEB-INF/lib/**'
    exclude 'WEB-INF/classes/**'
}
/* Change context path (base url). otherwise defaults to name of project */
jettyRunWar.contextPath = ''

关于web-applications - 如何在 gradle 中设置 webAppDirName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18273184/

相关文章:

gradle - 如何替换 gradle 的默认源文件夹?

gradle - 在gradle中,我们如何基于文件名替换文件中的 token

javascript - Silverlight HTML-JS-DOM 桥 : Real world use cases?

javascript - 我不能在 Android 上使用嵌入式 <style> CSS 吗?

python - SQLAlchemy(Postgresql) - 竞争条件

gradle - 如何在 Gradle 中创建包含项目 jars 和 war 的分发存档 (zip)

java - libgdx的gradlew在Fedora中不起作用

android - cordova gradle 6.0.1 错误 "Could not find com.android.tools.build:gradle:6.0.1"

web-applications - 对于 Tomcat 6,我的 Web 应用程序的 context.xml 是否需要位于 $catalina_base/conf/中?

android - 无法解析 com.google.firebase :firebase-crash:17. 0.2