当前位置: 首页 > 知识库问答 >
问题:

Gradle-如何从war中排除Web-INF/类

凌华奥
2023-03-14

我有一个相当简单的要求。我有以下项目布局:

project/build.gradle
 --src/main/java
 --src/main/res

我想做的是为project/src/main/java中的所有java文件创建一个jar

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'jetty'
apply plugin: 'war'

dependencies {
..
    compile 'com.fasterxml.jackson.core:jackson-core:2.3.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0'
..
}

jar {
    archiveName = 'hello.jar'
}

war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    webInf {
        from ('src/main/res') {
            include '**/*.*'
            into 'resources/'
        }
    }
}
war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    rootSpec.exclude ('WEB-INF/classes')
    ...
}
war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    classpath fileTree(dir:'build/classes/', exclude:'*.class')
    ...
}

使用from(“war”):

war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    from ('war') {
       exclude('WEB-INF/classes')
    }
}

直接执行“排除”:

war {
    dependsOn jar
    archiveName = 'hello.war'
    classpath fileTree(dir:'build/libs/',include:'*.jar')
    classpath configurations.compile
    exclude('WEB-INF/classes')
    ...
}

这些都是我在网上找到的建议--但似乎没有一个奏效。我做错了什么。

分级版本是2.12。

共有1个答案

上官琦
2023-03-14

下面是对我起作用的东西,但是你仍然会在战争捆绑包中看到一个(无害的)空包:

war {
    rootSpec.exclude('**/com/xxxxx/web/client/')
}
 类似资料: