You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Thierry B <jb...@tbzone.org> on 2009/01/19 11:40:02 UTC

how to exclude classes from package in target/classes to be copied to WAR in packaging

Hello,

I've created a maven project with eclipse.
My maven project has 3 source folders : 

- src/main/resources
- src/main/java
- src/test/java

When I use maven compile, it compiles all except the classes in
src/test/java, but as I use eclipse, when I  modify something in
src/test/java, it compiles it also in target/classes as maven.

The problem is that during war packaging, it includes all in target/classes
in my war so it includes test classes.

I'd like to use maven plugin war, to tell him to exlude all classes java in
src/test/java.

I read other threads that talking about not compile classes that we don't
want to have to packaging, but it's not pratical for me because eclipse will
compile all...

I try that in my pom.xml :

     <plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-war-plugin</artifactId>
		<version>2.0.2</version>
		<configuration>
			<excludes>
				<exclude>**/Exemple*.class</exclude>
			</excludes>
		</configuration>
	  </plugin>

and I also try that :

     <plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-war-plugin</artifactId>
		<version>2.0.2</version>
		<configuration>
			<excludes>
				<exclude>target/classes/com/pv/rules/test/*.*</exclude>
			</excludes>
		</configuration>
	  </plugin>

but it doesn't work.

To be more precise on my structure, on my source folder stc/test/java, I've
created a package com.pv.rules.test where I put a test java classe.

Do you have an idea?

Thanks :-)






-- 
View this message in context: http://www.nabble.com/how-to-exclude-classes-from-package-in-target-classes-to-be-copied-to-WAR-in-packaging-tp21540465p21540465.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: how to exclude classes from package in target/classes to be copied to WAR in packaging

Posted by Deron Eriksson <jo...@codestrategies.com>.
If Eclipse is automatically generating classes in target/classes from your
classes in src/test/java, I think there is a problem, since src/test/java
classes should end up in target/test-classes. I would recommend

(1) running eclipse:eclipse on your project (to update your Eclipse
.classpath) and then
(2) perform a clean (to clean out the old files in target/classes).

As an example, if I execute 'mvn eclipse:eclipse' on a web project of mine,
my Eclipse project .classpath file ends up with the following:
...
  <classpathentry kind="src" path="src/main/java"/>
  <classpathentry kind="src" path="src/test/java"
output="target/test-classes"/>
  <classpathentry kind="output" path="target/classes"/>
...

Notice that src/test/java classes go to target/test-classes.

After performing eclipse:eclipse and refreshing your project, your
.classpath should be similar to the above.

After this, you should perform a 'mvn clean' and refresh your project. You
should end up with
 target/classes (empty folder)
 target/test-classes (empty folder)

Now, if you perform a 'mvn clean package', you should see that your regular
classes end up in target/classes and your test classes end up in
target/test-classes. If you inspect your war file that is created, you
should see that it does not contain your test classes.

By the way, it's a good idea to run clean before running lifecycle commands
like 'package' since this ensures that old stuff is cleaned out when you
build your new artifact.

Deron Eriksson

AW: how to exclude classes from package in target/classes to be copied to WAR in packaging

Posted by "Lewis, Eric" <Er...@ipi.ch>.
This may be out of scope for this question, but why not use m2eclipse?
It separates main and test classes nicely and IMHO relieves you from all of these problems.

Best regards,
Eric 

> -----Ursprüngliche Nachricht-----
> Von: Deron Eriksson [mailto:jonderon@codestrategies.com] 
> Gesendet: Montag, 19. Januar 2009 14:18
> An: users@maven.apache.org
> Betreff: Re: how to exclude classes from package in 
> target/classes to be copied to WAR in packaging
> 
> 
> If Eclipse is automatically generating classes in 
> target/classes from your
> classes in src/test/java, I think there is a problem, since 
> src/test/java
> classes should end up in target/test-classes. I would recommend
>  
> (1) running eclipse:eclipse on your project (to update your Eclipse
> .classpath) and then
> (2) perform a clean (to clean out the old files in target/classes).
>  
> As an example, if I execute 'mvn eclipse:eclipse' on a web 
> project of mine,
> my Eclipse project .classpath file ends up with the following:
> ...
>   <classpathentry kind="src" path="src/main/java"/>
>   <classpathentry kind="src" path="src/test/java"
> output="target/test-classes"/>
>   <classpathentry kind="output" path="target/classes"/>
> ...
>  
> Notice that src/test/java classes go to target/test-classes.
>  
> After performing eclipse:eclipse and refreshing your project, your
> .classpath should be similar to the above.
>  
> After this, you should perform a 'mvn clean' and refresh your 
> project. You
> should end up with 
>  target/classes (empty folder)
>  target/test-classes (empty folder)
>  
> Now, if you perform a 'mvn clean package', you should see 
> that your regular
> classes end up in target/classes and your test classes end up in
> target/test-classes. If you inspect your war file that is created, you
> should see that it does not contain your test classes.
>   
> Deron Eriksson
> 
> -- 
> View this message in context: 
> http://www.nabble.com/how-to-exclude-classes-from-package-in-t
> arget-classes-to-be-copied-to-WAR-in-packaging-tp21540465p2154
> 2863.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: how to exclude classes from package in target/classes to be copied to WAR in packaging

Posted by Deron Eriksson <jo...@codestrategies.com>.
If Eclipse is automatically generating classes in target/classes from your
classes in src/test/java, I think there is a problem, since src/test/java
classes should end up in target/test-classes. I would recommend
 
(1) running eclipse:eclipse on your project (to update your Eclipse
.classpath) and then
(2) perform a clean (to clean out the old files in target/classes).
 
As an example, if I execute 'mvn eclipse:eclipse' on a web project of mine,
my Eclipse project .classpath file ends up with the following:
...
  <classpathentry kind="src" path="src/main/java"/>
  <classpathentry kind="src" path="src/test/java"
output="target/test-classes"/>
  <classpathentry kind="output" path="target/classes"/>
...
 
Notice that src/test/java classes go to target/test-classes.
 
After performing eclipse:eclipse and refreshing your project, your
.classpath should be similar to the above.
 
After this, you should perform a 'mvn clean' and refresh your project. You
should end up with 
 target/classes (empty folder)
 target/test-classes (empty folder)
 
Now, if you perform a 'mvn clean package', you should see that your regular
classes end up in target/classes and your test classes end up in
target/test-classes. If you inspect your war file that is created, you
should see that it does not contain your test classes.
  
Deron Eriksson

-- 
View this message in context: http://www.nabble.com/how-to-exclude-classes-from-package-in-target-classes-to-be-copied-to-WAR-in-packaging-tp21540465p21542863.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: how to exclude classes from package in target/classes to be copied to WAR in packaging

Posted by Thierry B <jb...@tbzone.org>.
Hello,

I've found with thiis link : 
http://www.nabble.com/Excluding-certain-file-types-using-the-maven-war-plugin-td19947937.html#a19947937
http://www.nabble.com/Excluding-certain-file-types-using-the-maven-war-plugin-td19947937.html#a19947937
.

<excludes> should take a pattern, not a series of <exclude> elements... :)

So, I've put that :

<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-war-plugin</artifactId>
		<version>2.0.2</version>
		<configuration>
			<excludes>**/test/*.class</excludes>
		</configuration>
	  </plugin>

and it works :-)



Thierry B wrote:
> 
> Hello,
> 
> I've created a maven project with eclipse.
> My maven project has 3 source folders : 
> 
> - src/main/resources
> - src/main/java
> - src/test/java
> 
> When I use maven compile, it compiles all except the classes in
> src/test/java, but as I use eclipse, when I  modify something in
> src/test/java, it compiles it also in target/classes as maven.
> 
> The problem is that during war packaging, it includes all in
> target/classes in my war so it includes test classes.
> 
> I'd like to use maven plugin war, to tell him to exlude all classes java
> in src/test/java.
> 
> I read other threads that talking about not compile classes that we don't
> want to have to packaging, but it's not pratical for me because eclipse
> will compile all...
> 
> I try that in my pom.xml :
> 
>      <plugin>
> 		<groupId>org.apache.maven.plugins</groupId>
> 		<artifactId>maven-war-plugin</artifactId>
> 		<version>2.0.2</version>
> 		<configuration>
> 			<excludes>
> 				<exclude>**/Exemple*.class</exclude>
> 			</excludes>
> 		</configuration>
> 	  </plugin>
> 
> and I also try that :
> 
>      <plugin>
> 		<groupId>org.apache.maven.plugins</groupId>
> 		<artifactId>maven-war-plugin</artifactId>
> 		<version>2.0.2</version>
> 		<configuration>
> 			<excludes>
> 				<exclude>target/classes/com/pv/rules/test/*.*</exclude>
> 			</excludes>
> 		</configuration>
> 	  </plugin>
> 
> but it doesn't work.
> 
> To be more precise on my structure, on my source folder stc/test/java,
> I've created a package com.pv.rules.test where I put a test java classe.
> 
> Do you have an idea?
> 
> Thanks :-)
> 
> 
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-exclude-classes-from-package-in-target-classes-to-be-copied-to-WAR-in-packaging-tp21540465p21541182.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org