How do I exclude Maven resources when publishing from Eclipse WTP to a server?

735 views Asked by At

How do I make WTP exclude Maven resources in the src/main/resources folder, when it deploys or publishes to a server? For example, I created a few folders named src/main/resources/qa and src/main/resources/prod, and in there I have properties files. I want to use them for deployment, but I don't want them in the WAR file artifact.

By adding a resources stanza to my pom.xml, I can exclude those folders from Maven builds (e.g. when I run mvn package), and they won't show up in my WAR file artifact.

But, when I use the "Debug As.." approach with WTP to let Eclipse manage and attach to my local Tomcat server, I can see that WTP is publishing all the resources including my excluded folders in the local Tomcat server. I have watched the wtpwebapp folder, that is the deployment target WTP is using, disappear when I have removed my WAR artifact from the Eclipse server definition. Then, the excluded resources find their way back when I add the project back to the server.

I have tried explicitly excluding the folders with "**/qa/" and "**/prod/" entries in the Java Build path for my project on the appropriate source libraries, and in fact, recreating the Eclipse project using mvn eclipse:clean eclipse:eclipse -Dwtpversion=2.0 will add the build path exclusions for me automatically. They just don't seem to be honored when WTP publishes.

1

There are 1 answers

1
333kenshin On BEST ANSWER

@Greg,

One option to consider is having Maven instead of Eclipse WTP push the WAR to the server.

This might entail tradeoffs depending on what Eclipse is doing for you behind the scenes.

Then again, your desktop will more exactly mirror what happens in your CI build.

Anyway, this guide explains in good depth how to configure the tomcat7:deploy goal.

Here is a suggested pom.xml snippet to get you started:

<plugins>
    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
            <execution>
                <phase>deploy</phase>
                <goals>
                    <goal>redeploy</goal>
                </goals>
                <configuration>
                    <url>http://localhost:8080/manager/text</url>
                    <server>TomcatServer</server>
                    <path>/mkyongWebApp</path>
                </configuration>
            </execution>
        </execution>
    </plugin>
  </plugins>