You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Eric Daigneault <da...@gmail.com> on 2007/04/10 17:32:28 UTC

How to NOT include test resources in jar

Hi everybody,

I'm trying to package my projects and everything works fine except that 
test resources are systematically included in the jar.  No matter where 
I put them or what I declare in testResources they always end up in the 
jar.  This can me problematic as some of the test can be very extensive 
as they can include test databases of very big test files.  Since their 
only uses is for unit and specification testing there is absolutely no 
reason to include them in the final release.


The project is arranged as follows :

com.mypackage.pack.specific/
|
\-src
    |--main
    |      \-java
    |          \-- My source tree
    \--test
         \--java
               |-- My test source tree
               \--resources
                       |--unitTest
                       \--SpecTest

My problem is that the source tree from src/test is not included in the 
jar...  actually this is fine but the content of resources is included 
at the root of the jar..

The end result in the jar is the following :

specific-1.0.jar
    |--META-INF
    |        \--  ... pom and properties
    |--com.mypackage.pack
    |       \--My source tree compiled
    |--unitTest   <-- Why is this here ???
    \--SpecTest <--Why is this here too ???  want them removed

here is the effective POM from my latest attempt :


<?xml version="1.0"?><project>
  <parent>
    <artifactId>base</artifactId>
    <groupId>com.mypackage</groupId>
    <version>1.0</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mypackage.pack</groupId>
  <artifactId>specific</artifactId>
  <name>specific</name>
  <version>1.0</version>
  <url>http://maven.apache.org</url>
  <inceptionYear>2007</inceptionYear>
  <developers>
    <developer>
      <id>eric</id>
      <name>myself</name>
     </developer>
  </developers>
  <build>
    
<sourceDirectory>D:\workspace\com.mypackage.pack.specific\src\main\java</sourceDirectory>
    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
    
<testSourceDirectory>D:\workspace\com.mypackage.pack.specific\src\test\java</testSourceDirectory>
    
<outputDirectory>D:\workspace\com.mypackage.pack.specific\target\classes</outputDirectory>
    
<testOutputDirectory>D:\workspace\com.mypackage.pack.specific\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        
<directory>D:\workspace\com.mypackage.pack.specific\src\main\config</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>/src/test/java/resources</directory>
      </testResource>
    </testResources>
    <directory>D:\workspace\com.mypackage.pack.specific\target</directory>
    <finalName>specific-1.0</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-help-plugin</artifactId>
        <version>2.0.1</version>
      </plugin>
    </plugins>
  </build>
  <repositories>
     <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Plugin Repository</name>
      <url>http://repo1.maven.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.mypackage</groupId>
      <artifactId>pack</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>
  <reporting>
    <outputDirectory>target/site</outputDirectory>
  </reporting>
 </project>

Thanks,

Éric

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


Re: How to specify where to copy particular files

Posted by franz see <fr...@gmail.com>.
Good day,

In addition, there's a difference between

<resource>
  <directory>src/main/resources/</directory>
  <includes>
    <include>foo/bar.xml</include>
  </includes>
</resource>

And

<resource>
  <directory>src/main/resources/foo</directory>
  <includes>
    <include>bar.xml</include>
  </includes>
</resource>

The first one would result to a

target/classes/foo/bar.xml

while the second, to a

target/classes/bar.xml

Thus, if you want a certain directory copied to target\classes ( or
target\test-classes for test resources ), specify in your
<resource><directory/></resource> the path to that certain directory.

Cheers,
Franz


Rod Mclaughlin wrote:
> 
> Thanks again, guys. Plus you can specify where the files come from if 
> you don't want to put them in src/main/resources:
> 
>  <resources>
>                 <resource>
>                 <targetPath>foo</targetPath>
>                 <directory>${basedir}/src/main/java/foo</directory>
>                 <includes>
>                     <include>*.xml</include>
>                 </includes>
>                 </resource>
> ...
> </resources>
> 
> ------------------------------------------------
> Two ways:
> 
> * First is to save the bar.xml into src/main/resources/foo/bar.xml so you
> don't have to configure anything.
> 
> * Second is to use <targetPath>foo</targetPath> in <resource>
> 
> 
> On 4/10/07, Rod Mclaughlin <Ro...@omnimedix.org> wrote:
> 
> I know how to make Maven copy a buncha files into the classpath, but
> does anyone know how to make it copy into a particular folder? Eg. I want
> src/main/java/foo/bar.xml to go in
> target/classes/foo/
> next to bar.class?
> 
> Thanks for any assistance. I have of course googled for it, to no avail.
> 
>        <resources>
>                <resource>
>                <directory>${basedir}/war/WEB-INF</directory>
>                <includes>
>                    <include>*.properties</include>
>                    <include>*.xml</include>
>                </includes>
>                </resource>
>        </resources>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-NOT-include-test-resources-in-jar-tf3553707s177.html#a9931972
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