Domanda

I have a multi-module maven project like this :

project
  project-core
  project-webapp

project-core is a dependency of project-webapp. When building project-core, I exclude some elements from the final jar. When I build and deploy the whole project with maven (through m2eclipse), everything is fine.

However, if I build and deploy with WTP, the resource filtering is skipped.

The only work around I have found so far is to disable workspace resolution from m2eclipse. This way, WTP builds the final war with the jar built by maven. The major drawback with this workaround is that I must install, update project each time I modify the project-core source code.

How can I force WTP to filter out resources from project-core ?

project/project-core/pom.xml

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>project</artifactId>
        <groupId>com.company.project</groupId>
        <version>1.0.0</version>
    </parent>

    <artifactId>project-core</artifactId>
    <name>project-core</name>
    <version>${version.project}</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
                // (huge) dependencies list ...
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <excludes>
                        <exclude>file.properties</exclude>
                        <exclude>DIR/file.xml</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
              // repositories ...
    </repositories>
</project>

EDIT:

However, if I build and deploy with WTP, the resource filtering is skipped.

Actually I was not doing the filtering at the right phase. The resources were filtered only during the jar building. Thanks to @Samuel EUSTACHI, I filter now the resources when they are copied to the target folder. Here how I did it :

project/project-core/pom.xml

        <build>
             <!--
                  I removed completely the plugins node and
                  replace it with the resources node
             -->

             <resources>
                 <resource>
                 <directory>src/main/resources</directory>
                     <excludes>
                        <exclude>file.properties</exclude>
                        <exclude>DIR/file.xml</exclude>
                    </excludes>
                 </resource>
             </resources>
        </build>
È stato utile?

Soluzione

My guess would be that WTP does not perform the actual jar build, but rather works with the available resources (probably in target).

It is uncommon to exclude some files from the jar. You could exclude these files from the preceding phases (process-resources ?) or, if you only need these files for Unit Test, move them in test.

It really depends why you decided to exclude them from the jar (you must have a good reason, but it would help to know why).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top