Reputation: 83
I have a quite specific problem. I created a webapp and want to have a jar build of the classes additionally to the web war. No problem, I did that by:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
By that also the resources from src/main/resources go into the jar. But as these resources are only for this web application, I don't want them in the jar. I could move them to the webapp src folder, but I need filtering on the properties file, so it has to be a resources folder and therefore gets included by a war/jar build.
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
I tried to exclude them by configuring the maven-jar-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<excludes>
<exclude>**properties</exclude>
</excludes>
</configuration>
</plugin>
Works fine for a singular jar build by jar:jar, but unfortunatly not for the jar build done by the install phase.
Is there a way to apply these configurations to the maven-war-plugin?
I know I could extend the configuration by adding executions for building a jar, installing it locally and for deploying it to a remote repository, but that's a little mess up.
Any help is welcome.
Upvotes: 2
Views: 1153
Reputation: 54427
One way to do this would be by moving the Java sources to a separate project, which you then include in the WAR project as a dependency. This way, you have control over what goes into the JAR file and you could keep the other files in the WAR project, apply filtering etc.
I found that separating functionality into fine-grained projects is often the best way to solve things instead of setting up multiple plugins with complex configuration to do the same. If it requires a complex setup, it's probably the wrong way. Try to keep it simple :-)
Upvotes: 2