Wrong files added to WAR package using Gradle

2019-05-06 04:34发布

问题:

I'm using Gradle 1.5 and I'm trying to adapt the WAR plugin to an Eclipse dynamic project.

When the WAR is exported by eclipse it has the xhtml files straight on the root of the war file, and I managed to do that with Gradle.

But on my Gradle exported war I have the xhtml files duplicated inside WEB-INF/classes along with my .class files

I only want to have my .class files in that folder, but I haven't found a way to do it

Here's the relevant part of my build.gradle file

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

webAppDirName = 'WebContent'

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

eclipse {
    // my eclipse plugin config..
}

dependencies {
    // my dependencies config.
}

The only customization I have done to the war plugin was change the webAppDirName to point to my WebContent folder.

Does anyone know how to define what goes inside the WEB-INF/classes directory? I can't seem to get the hang of it.


EDIT I have managed to remove the .xhtml duplicates by referring the resources to my bin directory like this:

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

But I still have wrong files in my WEB-INF.

I have even this structure WEB-INF/classes/WEB-INF. I don't know why these folders are being added to my classes directory, since they don't exist in my bin

I want the classes in my bin to be in WEB-INF/classes and the static resources in my WebContent to be in the root of the WAR file

回答1:

By default, what goes into WEB-INF/classes is the output of the main source set (compiled classes and processed resources). Your build script declares an additional source directory (src), and keeps the default resource directory. Do you have any files under src/main/java or src/main/resources?



回答2:

Eclipse uses the bin folder as its output folder, so there's a possibility, that your files get mixed up this way.



标签: java war gradle