Maven - Exclude class files from war - maven-2

I have :
src/main/java/com.tuto
Class1.java
Class2.java
Class3.java
My pom is packaging a war.
So in my war, in WEB-INF/classes/com/tuto I found the 3 classes.
Now I want to exclude Class2.java
I tried
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<excludes>
<exclude>**/Class2.class</exclude>
</excludes>
</configuration>
</plugin>
But it's not working.
How can I do ?
Ok, so like Aaron tell me, this is working :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<packagingExcludes>**/Class2.class</packagingExcludes>
</configuration>
</plugin>
But ...
Let's take the problem by the other side : I want to exclude all except Class1 and Class3
So I tried
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<packagingIncludes>**/Class1.class,**/Class3.class</packagingIncludes>
</configuration>
</plugin>
and this time it's not working.

As the documentation says, you should use the packagingExcludes element instead.
Note that packagingExcludes doesn't use nested elements. Instead, the content is a "comma-separated list of Ant file set patterns".

From the documentation, excludes will take higher priority over includes. In your case, use packagingExcludes for excluding class2 explicitly.
<packagingExcludes>WEB-INF/classes/com/tuto/Class2.class</packagingExcludes>

The complete plugin xml should be like the following
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputDirectory>${build.output.directory}</outputDirectory>
<packagingExcludes>WEB-INF/classes/ItemConsumer.class</packagingExcludes>
</configuration>
</plugin>

add plugin to pom.xml - 100% working properly.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<!--package path you want to delete-->
<packagingExcludes>WEB-INF/classes/lk/**</packagingExcludes>
<webResources>
<resource>
<!--project build path-->
<directory>${project.basedir}/target/classes/</directory>
<filtering>true</filtering>
<includes><include>**/*.class</include></includes>
</resource>
</webResources>
</configuration>
</plugin>

Related

Not able to generate client code with wsdl2java and maven using CXF

I'm using maven cxf-codegen-plugin to generate client files from wsdl but not able to do so.
I want that all the wsdl files in the folder src/main/wsdl should be scanned and corresponding clients should be generated in separate folders. Please help.
My pom.xml is :
<build>
<finalName>someFileName</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.2.3</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>process-resources</phase>
<configuration>
<sourceRoot>src/main/java</sourceRoot>
<wsdlRoot>${basedir}/src/main/wsdl</wsdlRoot>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
here's how I'm doing it with version 2.7.4, and having the generated code created in different packages :
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/MyWsdl1.wsdl</wsdl>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>urn:mycompany:myproduct1:v1_0=com.my.project.product1</extraarg>
<extraarg>-p</extraarg>
<extraarg>http://www.w3.org/2001/XMLSchema=com.my.project.common</extraarg>
</extraargs>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/MyWsdl2.wsdl</wsdl>
<extraargs>
<extraarg>-client</extraarg>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>urn:mycompany:myproduct2:v1_0=com.my.project.product2</extraarg>
<extraarg>-p</extraarg>
<extraarg>http://www.w3.org/2001/XMLSchema=com.my.project.common</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Here's where you can find out more about the extra-args :
http://cxf.apache.org/docs/wsdl-to-java.html
For an automatic scan of the wsdl folder, this works good too :
<configuration>
<sourceRoot>${project.build.directory}/generated/src/main/java</sourceRoot>
<wsdlRoot>${basedir}/src/main/wsdl</wsdlRoot>
<includes>
<include>**/*.wsdl</include>
</includes>
</configuration>
Hope it helps!
I realize this is an old question, but I just ran into this, so I wanted to reply for the benefit of others. You are right on commenting out the <pluginManagement> tag see here. However for the error in Eclipse that says:
Plugin execution not covered by lifecycle configuration
You will need to install the m2e connector for build-helper-maven-plugin (click on the error, and Eclipse should guide you to install it)
I put plugins tag inside pluginManagement tag and error disappeared:
<pluginManagement>
<plugins>
<plugin>
..........................
</plugin>
</plugins>
</pluginManagement>

yuicompressor-maven-plugin not bounded to process-resources

I have been trying to figure out why yuicompressor-maven-plugin is not executed during "mvn package". I can execute it in an independent task as described in the link below but somehow the plugin does not get called from maven life cycle.
http://davidb.github.com/yuicompressor-maven-plugin/usage_compress.html
and here is the sample pom.xml I use,
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- yuicompressor-maven-plugin -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<id>compress</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<linebreakpos>-1</linebreakpos>
<encoding>UTF-8</encoding>
<nosuffix>true</nosuffix>
<force>true</force>
<jswarn>false</jswarn>
<webappDirectory>${project.build.directory}/minified</webappDirectory>
<aggregations>
<aggregation>
<insertNewLine>true</insertNewLine>
<output>${project.build.directory}/${project.build.finalName}/js/abc-min.js</output>
<includes>
<include>${basedir}/src/main/webapp/js/comments.txt</include>
<include>${project.build.directory}/minified/js/def.js</include>
</includes>
</aggregation>
</aggregations>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<warSourceExcludes>js/**/*.js,js/**/*.txt,css/**/*.css,css/**/*.txt</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
I have read similar posts but could not figure out why it's not bounded to "process-resources". Phase and Goal are explicitly set so not sure why it's not called. Is there a way to debug why yuicompressor-maven-plugin is not called during "mvn package"? I use maven 2.2.1. Perhaps the version of my Maven won't work with the plugin?
thanks for your help,
syamashi
You simply need to put the running out of the pluginManagement area into the usual plugins area like:
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
....
</plugin>
</plugins>
</build>
In pluginManagement you define only the default for plugin in particular the verison but you really don't bound to real execution. For other plugins etc. this works cause the are alreay defined in the build area of the supoer pom so this give you the opportunity to redefine them via pluginManagement but not with a plugin which never has been part of any build area.

How do I build only one JAR file with classifier?

I'm using Maven 2 and maven-jar-plugin to build my jar.
I'd like to generate only a jar with a classifier. Is it possible?
In my example I'd like to generate only the myjar-another-1.0.jar but not myjar-1.0.jar.
After take a look at this question I tried to skip the default-jar. But this seems to work only with version 3 of Maven (haven't tried thou.
The parent is to do the
<modules>
Thanks all!
Here is the relevant piece of my pom.xml:
Also tried in the global configuration segment.
<project>
<!-- Definition of the Parent (only an aggregator) -->
<build>
<plugins>
<!-- <artifactId>maven-bundle-plugin</artifactId> -->
<!-- surefire -->
<!-- <artifactId>maven-source-plugin</artifactId> -->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<classifier>another</classifier>
</configuration>
<executions>
<execution>
<id>test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Just use it for the plugin element:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<classifier>another</classifier>
</configuration>
</plugin>
</plugins>

where are my class files gone, using the maven-compiler-plugin?

I'm trying to build a jar file using 2 different source directories. So I'm using the maven-compiler-plugin. Here is my config:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<includes>
<include>**/*</include>
<include>src/main/java/**/*.java</include>
<include>../syncrpc/src/main/java/**/*.java</include>
</includes>
</configuration>
</plugin>
It builds alright but my jar file is empty (almost)... and my usual "target/classes" dir is empty. I suppose by default the compiler creates this directory and puts all the packages with the built classes. Can I do manually when I use the maven-compiler-plugin?
Thank you
Found a solution:
build-helper-maven-plugin
Basically, use the helper plugin instead, and it works perfectly.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<source>../syncrpc/src/main/java/com/gdevelop/gwt/syncrpc</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

Emma runtime controller doesnt start

My primary goal is to get code coverage using EMMA on a running web application using CTL coverage.get.
I use emma maven plugin.
So, I deploy my web application with instrumented code.
In tomcat log is see:
EMMA: collecting runtime coverage data ...
but there is no:
EMMA: runtime controller started on port [47653]
Which means that Im not able to use ctl as nobody is listening for it.
What could be the reason of runtime controller not starting?
My parent pom.xml:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>instrument</id>
<phase>process-test-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
<reporting>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-3</version>
<inherited>true</inherited>
</plugin>
...
</plugins>
</reporting>
...
</project>
Thanks in advance. Any hint is highly appreciated.
Try this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<systemPropertyVariables combine.children="append">
<emma.rt.control>true|false</emma.rt.control>
</systemPropertyVariables>
</configuration>
</plugin>