Depending on how much flexability you have to move files around, I would
suggest moving these property and xml files to src/test/resources and
removing the testResources block entirely.


-----Original Message-----
From: Martin Aspeli [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 01, 2006 10:39 AM
To: users@maven.apache.org
Subject: Referencing .properties files in the CLASSPATH in test


Hi guys,

I have some unit tests that do things like this:

InputStream stream =
ClassLoader.getSystemResourceAsStream("TestDBSetup.properties");
assertNotNull("Could not load TestDBSetup.properties from classpath",
stream);
Properties dbProperties = new Properties();
dbProperties.load(stream);

TestDBSetup.properties lives in src/main/test/resources.

In Eclipse, this works fine. However, when I execute mvn test, it
doesn't
work. TestDBSetup.properties is no copied to target/test-classes
(Eclipse
does it, though). Even if I put it there manually, the ClassLoader can't
find it when I run 'mvn test', presumably because it's not on the
CLASSPATH?

In a similar vein, I have some xml files in
src/main/test/java/com/foo/bar
that need to be in the CLASSPATH under target/test-classes/com/foo/bar.

My POM is like so:

<?xml version="1.0"?><project>
  
  <parent>
    <artifactId>MyParentProject</artifactId>
    <groupId>com.foo.bar</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.foo.bar</groupId>
  <artifactId>MyDatabasePackage</artifactId>
  <name>MyDatabasePackage</name>
  <version>1.1-SNAPSHOT</version>
  <url>http://foo.com</url>

  <build>
    <finalName>MyDatabasePackage</finalName>
    
    <resources>
     <resource>
       <directory>${build.sourceDirectory}</directory>
       <includes>
         <include>**/*.properties</include>
       </includes>
    </resource>
     </resources>
     
    <testResources>
        <testResource>
       <directory>${build.sourceDirectory}</directory>
       <includes>
         <include>**/*.properties</include>
       </includes>
     </testResource>
   </testResources> 
     
    
    
  </build>
  
  <dependencies>
    
    <!--  Common resources -->
    <dependency>
      <groupId>com.foo.bar</groupId>
      <artifactId>MyProductCommon</artifactId>
      <version>1.1-SNAPSHOT</version>
    </dependency>
    
    <!--  Database connectivity -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>3.1.11</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate</artifactId>
      <version>3.1rc3</version>
    </dependency>
    
    <!--  Unit testing frameworks -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>dbunit</groupId>
      <artifactId>dbunit</artifactId>
      <version>2.1</version>
      <scope>test</scope>
    </dependency>
    
    
    <!--  In-memory JNDI implementation; used for testing -->
    <dependency>
      <groupId>directory-naming</groupId>
      <artifactId>naming-core</artifactId>
      <version>0.8</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>directory-naming</groupId>
      <artifactId>naming-factory</artifactId>
      <version>0.8</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>directory-naming</groupId>
      <artifactId>naming-java</artifactId>
      <version>0.8</version>
      <scope>test</scope>
    </dependency>
    
  </dependencies>
</project>

Any help greatly appreciated!

Martin
--
View this message in context:
http://www.nabble.com/Referencing+.properties+files+in+the+CLASSPATH+in+
test-t1717149.html#a4663313
Sent from the Maven - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to