You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ray Wenderlich <ra...@gmail.com> on 2007/08/14 06:44:07 UTC

Resources and JUnit

Hi all,

I am testing a class that is using a .properties file that I have
placed in src\main\resources.  I am loading it via:

InputStream is =
getClass().getClassLoader().getResourceAsStream("add.properties");

The .properties file gets copied to target\classes\add.properties, and
when I create a package and run the class everything works fine.  The
problem is if I try to run a junit test against the class, at that
point the class cannot find the .properties file.

I ran mvn test with -X and got the following:

[DEBUG] Test Classpath :
[DEBUG]   C:\Projects\Experiments\add-test\target\test-classes
[DEBUG]   C:\Projects\Experiments\add-test\target\classes
[DEBUG]   C:\Documents and
Settings\rwenderlich\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar

I am using a basic POM I generated with the mvn archetype:create, so
I'm using the default resources settings.  I am using Maven 2.0.8.

Any ideas what's going on here?  I've read the other forum postings on
the subject and tried a bunch of different things to no avail.

Thanks!

--Ray

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


Re: Resources and JUnit

Posted by Ray Wenderlich <ra...@gmail.com>.
Wow you are right - there was an error in my test itself, lol!  Sorry
for the confusion, I thought I had everything set up right :]

On 8/14/07, Lalor, Brian <Br...@fmr.com> wrote:
> > -----Original Message-----
> > From: Ray Wenderlich [mailto:ray.wenderlich@gmail.com]
> > Sent: Tuesday, August 14, 2007 12:44 AM
> > To: users@maven.apache.org
> > Subject: Resources and JUnit
> >
> > Hi all,
> >
> > I am testing a class that is using a .properties file that I have
> > placed in src\main\resources.  I am loading it via:
> >
> > InputStream is =
> > getClass().getClassLoader().getResourceAsStream("add.properties");
> >
> > The .properties file gets copied to target\classes\add.properties, and
> > when I create a package and run the class everything works fine.  The
> > problem is if I try to run a junit test against the class, at that
> > point the class cannot find the .properties file.
> >
> > I ran mvn test with -X and got the following:
> >
> > [DEBUG] Test Classpath :
> > [DEBUG]   C:\Projects\Experiments\add-test\target\test-classes
> > [DEBUG]   C:\Projects\Experiments\add-test\target\classes
> > [DEBUG]   C:\Documents and
> > Settings\rwenderlich\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar
> >
> > I am using a basic POM I generated with the mvn archetype:create, so
> > I'm using the default resources settings.  I am using Maven 2.0.8.
> >
> > Any ideas what's going on here?  I've read the other forum postings on
> > the subject and tried a bunch of different things to no avail.
>
> What's the exact error you're getting in your code?  I'm doing something similar in my current project and it works just fine.  You're retrieving it from the classpath, and that directory's on the classpath, so it should work...  You do see the file in target/classes after the test goal runs, right?
>
> ---------------------------------------------------------------------
> 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: Resources and JUnit

Posted by "Lalor, Brian" <Br...@fmr.com>.
> -----Original Message-----
> From: Ray Wenderlich [mailto:ray.wenderlich@gmail.com] 
> Sent: Tuesday, August 14, 2007 12:44 AM
> To: users@maven.apache.org
> Subject: Resources and JUnit
> 
> Hi all,
> 
> I am testing a class that is using a .properties file that I have
> placed in src\main\resources.  I am loading it via:
> 
> InputStream is =
> getClass().getClassLoader().getResourceAsStream("add.properties");
> 
> The .properties file gets copied to target\classes\add.properties, and
> when I create a package and run the class everything works fine.  The
> problem is if I try to run a junit test against the class, at that
> point the class cannot find the .properties file.
> 
> I ran mvn test with -X and got the following:
> 
> [DEBUG] Test Classpath :
> [DEBUG]   C:\Projects\Experiments\add-test\target\test-classes
> [DEBUG]   C:\Projects\Experiments\add-test\target\classes
> [DEBUG]   C:\Documents and
> Settings\rwenderlich\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar
> 
> I am using a basic POM I generated with the mvn archetype:create, so
> I'm using the default resources settings.  I am using Maven 2.0.8.
> 
> Any ideas what's going on here?  I've read the other forum postings on
> the subject and tried a bunch of different things to no avail.

What's the exact error you're getting in your code?  I'm doing something similar in my current project and it works just fine.  You're retrieving it from the classpath, and that directory's on the classpath, so it should work...  You do see the file in target/classes after the test goal runs, right?

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


Re: Resources and JUnit

Posted by Steven Rowe <sa...@syr.edu>.
Ray Wenderlich wrote:
> I am using Maven 2.0.8.

Wow, where can I get me one of them?  :)

(2.0.7 is the most recent release.)

Steve

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