0

I want to exclude a folder from being added to the .war-file based on the profile set.

Filtering in Maven War Plugin

I have the following configuration:

    <profile>
        <id>tomcat</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <property>
                <name>env</name>
                <value>tomcat</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <webResources>
                        <resource>
                            <directory>src/main/webapp</directory>

                            <excludes>
                                <exclude>docs/*</exclude>
                            </excludes>
                        </resource>
                        </webResources>
                    </configuration>
                </plugin>
            </plugins>
            <finalName>somename</finalName>
        </build>

        <properties>
            <webXmlPath>${basedir}/src/main/config/tomcat</webXmlPath>
            <profileDir>tomcat</profileDir>
        </properties>
    </profile>

Plugin-configuration:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <webXml>${webXmlPath}/web.xml</webXml>
                <webResources>
                    <resource>
                        <directory>src/main/webapp</directory>
                        <filtering>true</filtering>
                        <excludes>
                            <exclude>**/js/*</exclude>
                            <exclude>**/css/*</exclude>
                            <exclude>**/fonts/*</exclude>
                            <exclude>**/web.xml</exclude>
                            <exclude>**/config/*</exclude>
                        </excludes>
                    </resource>
                </webResources>
                <nonFilteredFileExtensions>
                    <nonFilteredFileExtension>gif</nonFilteredFileExtension>
                    <nonFilteredFileExtension>ico</nonFilteredFileExtension>
                    <nonFilteredFileExtension>jpg</nonFilteredFileExtension>
                    <nonFilteredFileExtension>png</nonFilteredFileExtension>
                    <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
                    <nonFilteredFileExtension>otf</nonFilteredFileExtension>
                    <nonFilteredFileExtension>eot</nonFilteredFileExtension>
                    <nonFilteredFileExtension>svg</nonFilteredFileExtension>
                    <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
                    <nonFilteredFileExtension>woff</nonFilteredFileExtension>
                </nonFilteredFileExtensions>
            </configuration>
        </plugin>

The docs-folder should be filtered, but it is present in the built-war file. I also tried

<warSourceExcludes>docs/**</warSourceExcludes>

but this did not work either.

This is the debug output:

[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-war-plugin:2.2:war' with basic configurator -->
[DEBUG]   (s) archiveClasses = false
[DEBUG]   (s) attachClasses = false
[DEBUG]   (s) cacheFile = C:\dev\workspaces\pep3_intellij\target\war\work\webapp-cache.xml
[DEBUG]   (s) classesClassifier = classes
[DEBUG]   (s) classesDirectory = C:\dev\workspaces\pep3_intellij\target\classes
[DEBUG]   (f) escapedBackslashesInFilePath = false
[DEBUG]   (s) failOnMissingWebXml = true
[DEBUG]   (f) filteringDeploymentDescriptors = false
[DEBUG]   (s) nonFilteredFileExtensions = [gif, ico, jpg, png, pdf, otf, eot, svg, ttf, woff]
[DEBUG]   (s) outputDirectory = C:\dev\workspaces\pep3_intellij\target
[DEBUG]   (s) primaryArtifact = true
[DEBUG]   (s) project = MavenProject: <censored>:0.4 @ C:\dev\workspaces\pep3_intellij\pom.xml
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@138684e7
[DEBUG]   (s) warName = pep
[DEBUG]   (s) useCache = false
[DEBUG]   (s) warSourceDirectory = C:\dev\workspaces\pep3_intellij\src\main\webapp
[DEBUG]   (s) warSourceIncludes = **
[DEBUG]   (s) directory = src/main/webapp
[DEBUG]   (s) excludes = [docs/**]
[DEBUG]   (s) filtering = true
[DEBUG]   (s) webResources = [Resource {targetPath: null, filtering: true, FileSet {directory: src/main/webapp, PatternSet [includes: {}, excludes: {docs/**}]}}]
[DEBUG]   (s) webappDirectory = C:\dev\workspaces\pep3_intellij\target\pep
[DEBUG]   (s) webXml = C:\dev\workspaces\pep3_intellij\src\main\config\tomcat\web.xml
[DEBUG]   (s) workDirectory = C:\dev\workspaces\pep3_intellij\target\war\work
[DEBUG] -- end configuration --

Profile is selected correctly, checked via mvn help:active-profiles

[INFO] Active Profiles for Project '<myproject>:0.4':
The following profiles are active:

- tomcat (source: <myproject>:0.4)

Also i am a bit confused about the - property, did not find a good explanation for it, the only thing close to it was Filtering in Maven War Plugin, but it didn't explain when and why to use .

Community
  • 1
  • 1
stefan
  • 23
  • 1
  • 7
  • Which maven command did you use for the build? What is the output if you use the same maven command but with this goal instead: `help:active-profiles`. This should indicate if your maven run includes your profile or not. – hotzst Oct 07 '15 at 13:01
  • i added the output of mvn help:active-profiles at the end of the question, the profile is selected – stefan Oct 07 '15 at 16:05
  • have you tried the solution that is described in http://stackoverflow.com/questions/27965578/apache-maven-resources-plugin-exclude-a-directory ? – lkiraly Oct 30 '15 at 19:56

0 Answers0