Discussion:
How to exclude the contents from WEB-INF/classes from being copied over?
Jim Sellers
2007-09-07 20:04:01 UTC
Permalink
Hello.

While using MyEclipse with maven, I have the eclipse plug-in keeping the
output directory as WEB-INF/classes so that I can still work with hot
deploys.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<outputDirectory>
src/main/webapp/WEB-INF/classes
</outputDirectory>
<plugin>

Eclipse copies the contents of both src/main and src/test to this location
so the classes directory will contain *Test.java as well as *.java.

When I do a mvn package on the war (outside of eclipse) maven copies
everything in the webapp directory over, and then puts in all the non-test
classes. However, since the WEB-INF/classes dir wasn't empty (because
eclipse is using it) all my tests and test resources get copied over as
well.

I've tried:
1) using the clean plug-in but that means when I switch back over to eclipse
I have to do a full clean on that project
2) using an exclude filter for the war plug-in, but have not had any luck
with that.

Does anyone have a working solution to this?

Thanks for all your time and help!
Jim
Thorsten Heit
2007-09-10 10:53:32 UTC
Permalink
Hi,
Post by Jim Sellers
While using MyEclipse with maven, I have the eclipse plug-in keeping the
output directory as WEB-INF/classes so that I can still work with hot
deploys.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<outputDirectory>
src/main/webapp/WEB-INF/classes
</outputDirectory>
<plugin>
Eclipse copies the contents of both src/main and src/test to this location
so the classes directory will contain *Test.java as well as *.java.
When I do a mvn package on the war (outside of eclipse) maven copies
everything in the webapp directory over, and then puts in all the non-test
classes. However, since the WEB-INF/classes dir wasn't empty (because
eclipse is using it) all my tests and test resources get copied over as
well.
Sure, because Maven treats them as web resources that have to be packaged into your WAR file...
Post by Jim Sellers
1) using the clean plug-in but that means when I switch back over to eclipse
I have to do a full clean on that project
2) using an exclude filter for the war plug-in, but have not had any luck
with that.
Does anyone have a working solution to this?
Not a solution, but some questions:

1) Why don't you just use the standard Maven directory for the compiled classes? This shouldn't prevent you from hot deploying changes...

2) Have you configured your desired output directory in your pom.xml so that Maven compiles your classes to the same directory?

<build>
...
<outputDirectory>...</outputDirectory>
<testOutputDirectory>...</testOutputDirectory>
</build>

3) If you really need to compile to WEB-INF/classes, have you tried configuring the Maven WAR plugin to exclude that directory when packaging web resources? See [1]


[1] http://maven.apache.org/plugins/maven-war-plugin/faq.html#webresourcesexclude


Regards

Thorsten
Jim Sellers
2007-09-10 18:51:37 UTC
Permalink
Thanks for the reply!

1) When I left the eclipse output directory as target MyEclipse got very
confused and I had a lot of issues, especially switching between eclipse and
maven builds.

2) No, I have not changed the maven output directories. This still goes to
the default target directories. We're keeping the "built by maven" output
(target/classes and target/test-classes) and the "built by eclipse"
(src/main/webapp/WEB-INF/classes) separate.

3) Yes, I have tried to get the exclude to work for the web resources, but
with no success. All examples are for additional web resource folder, so I
wonder if that's got anything to do with it. (??) Has anyone had any
experience excluding files / directories from src/main/webapp?

Here are some of the things that I have tried, none of which work. :-(
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<!--
<excludes>
<exclude>**/WEB-INF/classes/**</exclude>
</excludes>
-->
<!--
<webResources>
<resource>
<directory>src/main/webapp/</directory>
<excludes>
<exclude>**/WEB-INF/classes/**</exclude>
</excludes>
</resource>
</webResources>
-->
<webResources>
<resource>
<directory>
src/main/webapp/WEB-INF/classes/
</directory>
<excludes>
<exclude>**</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>


Thanks for all your time and help!
Jim
Post by Jim Sellers
Hi,
Post by Jim Sellers
While using MyEclipse with maven, I have the eclipse plug-in keeping the
output directory as WEB-INF/classes so that I can still work with hot
deploys.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<outputDirectory>
src/main/webapp/WEB-INF/classes
</outputDirectory>
<plugin>
Eclipse copies the contents of both src/main and src/test to this
location
Post by Jim Sellers
so the classes directory will contain *Test.java as well as *.java.
When I do a mvn package on the war (outside of eclipse) maven copies
everything in the webapp directory over, and then puts in all the
non-test
Post by Jim Sellers
classes. However, since the WEB-INF/classes dir wasn't empty (because
eclipse is using it) all my tests and test resources get copied over as
well.
Sure, because Maven treats them as web resources that have to be packaged
into your WAR file...
Post by Jim Sellers
1) using the clean plug-in but that means when I switch back over to eclipse
I have to do a full clean on that project
2) using an exclude filter for the war plug-in, but have not had any
luck
Post by Jim Sellers
with that.
Does anyone have a working solution to this?
1) Why don't you just use the standard Maven directory for the compiled
classes? This shouldn't prevent you from hot deploying changes...
2) Have you configured your desired output directory in your pom.xml so
that Maven compiles your classes to the same directory?
<build>
...
<outputDirectory>...</outputDirectory>
<testOutputDirectory>...</testOutputDirectory>
</build>
3) If you really need to compile to WEB-INF/classes, have you tried
configuring the Maven WAR plugin to exclude that directory when packaging
web resources? See [1]
[1]
http://maven.apache.org/plugins/maven-war-plugin/faq.html#webresourcesexclude
Regards
Thorsten
---------------------------------------------------------------------
Thorsten Heit
2007-09-10 21:25:05 UTC
Permalink
Hi,
Post by Jim Sellers
1) When I left the eclipse output directory as target MyEclipse got very
confused and I had a lot of issues, especially switching between eclipse and
maven builds.
Just for curiosity: What kind of errors?
For testing purposes on one of our company's projects I let Eclipse
compile the project stuff into the standard Maven output directory
(target/classes), but never encountered any problems with that...
Post by Jim Sellers
3) Yes, I have tried to get the exclude to work for the web resources, but
with no success. All examples are for additional web resource folder, so I
wonder if that's got anything to do with it. (??) Has anyone had any
experience excluding files / directories from src/main/webapp?
Here are some of the things that I have tried, none of which work. :-(
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<!--
<excludes>
<exclude>**/WEB-INF/classes/**</exclude>
</excludes>
-->
<!--
<webResources>
<resource>
<directory>src/main/webapp/</directory>
<excludes>
<exclude>**/WEB-INF/classes/**</exclude>
</excludes>
</resource>
</webResources>
-->
<webResources>
<resource>
<directory>
src/main/webapp/WEB-INF/classes/
</directory>
<excludes>
<exclude>**</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
According to the examples in [1] this looks correct. Can you try the
following snippet and see whether that works?

<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<excludes>
<exclude>WEB-INF/classes/**</exclude>
</excludes>
</resource>
</webResources>
</configuration>


[1]
http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html



HTH

Thorsten
Jim Sellers
2007-09-10 21:41:24 UTC
Permalink
Hi Thorsten!

I'm trying to remember exactly what the issues that came up while having
maven and eclipse build to the same location, but I can't remember specifics
other than one tool or the other would get confused if the other changed the
source. It was at least 6 months ago and I didn't document it. :-(

Thanks for the code snip-it. I tried that and cannot get it to work even
though it *looks* like it should.
This is a snip of the debug output:
[DEBUG] (s) warSourceDirectory = c:\path\to\war-project\src\main\webapp
[DEBUG] (s) directory = c:\path\to\war-project/src/main/webapp
[DEBUG] (s) excludes = [WEB-INF/classes/**]

One thing that I did notice is that I had locked down to version 2.0 in some
of my original tests. I removed the <version/> tag but still no luck. :-(

Thanks for your time!
Jim
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Post by Jim Sellers
1) When I left the eclipse output directory as target MyEclipse got very
confused and I had a lot of issues, especially switching between eclipse
and
Post by Jim Sellers
maven builds.
Just for curiosity: What kind of errors?
For testing purposes on one of our company's projects I let Eclipse
compile the project stuff into the standard Maven output directory
(target/classes), but never encountered any problems with that...
Post by Jim Sellers
3) Yes, I have tried to get the exclude to work for the web resources,
but
Post by Jim Sellers
with no success. All examples are for additional web resource folder,
so I
Post by Jim Sellers
wonder if that's got anything to do with it. (??) Has anyone had any
experience excluding files / directories from src/main/webapp?
Here are some of the things that I have tried, none of which work. :-(
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<!--
<excludes>
<exclude>**/WEB-INF/classes/**</exclude>
</excludes>
-->
<!--
<webResources>
<resource>
<directory>src/main/webapp/</directory>
<excludes>
<exclude>**/WEB-INF/classes/**</exclude>
</excludes>
</resource>
</webResources>
-->
<webResources>
<resource>
<directory>
src/main/webapp/WEB-INF/classes/
</directory>
<excludes>
<exclude>**</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
According to the examples in [1] this looks correct. Can you try the
following snippet and see whether that works?
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp</directory>
<excludes>
<exclude>WEB-INF/classes/**</exclude>
</excludes>
</resource>
</webResources>
</configuration>
[1]
http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
HTH
Thorsten
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkbltjEACgkQQvObkgCcDe1PAgCg9sZNyQ3mCyTgEkTAjc0L9V3d
sKMAoIjIOH8ca9I/bsXQVl35BCIfGWaP
=XigS
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
Thorsten Heit
2007-09-10 22:03:56 UTC
Permalink
Hi Jim,
Post by Jim Sellers
I'm trying to remember exactly what the issues that came up while having
maven and eclipse build to the same location, but I can't remember specifics
other than one tool or the other would get confused if the other changed the
source. It was at least 6 months ago and I didn't document it. :-(
*sigh*
Post by Jim Sellers
Thanks for the code snip-it. I tried that and cannot get it to work even
though it *looks* like it should.
[DEBUG] (s) warSourceDirectory = c:\path\to\war-project\src\main\webapp
[DEBUG] (s) directory = c:\path\to\war-project/src/main/webapp
[DEBUG] (s) excludes = [WEB-INF/classes/**]
One thing that I did notice is that I had locked down to version 2.0 in some
of my original tests. I removed the <version/> tag but still no luck. :-(
Can you try version 2.0.2 of the WAR plugin? This is the newest version
actually available on central repo...

I just saw that there are a couple of issues in Jira for WAR plugin
concerning resources:

* http://jira.codehaus.org/browse/MWAR-29
* http://jira.codehaus.org/browse/MWAR-60
* http://jira.codehaus.org/browse/MWAR-109

Your problem seems to be similar to MWAR-60. So if version 2.0.2 doesn't
work, what about giving 2.0.3-SNAPSHOT or 2.1-alpha-1-SNAPSHOT a try?


HTH

Thorsten

Loading...