You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Rossmanith, Philipp" <ph...@t-systems.es> on 2007/05/14 09:59:36 UTC

RE: Problems with loading non-Java resources from classpath in JUnit tests

Hi,

My resource file (the properties file I am trying to load) is located
under {root}src\test\resources. Compiling with Maven puts it under
{root}\target\test-classes, along with the Java class files for the unit
tests.

I also tried to run the tests with the properties-file placed in
{root}src\main\resources, but it didn't work, either.

Any other suggestions?

Thanks in advance,
Ciao,
Philipp

> -----Mensaje original-----
> De: Wayne Fay [mailto:waynefay@gmail.com]
> Enviado el: domingo, 13 de mayo de 2007 23:36
> Para: Maven Users List
> Asunto: Re: Problems with loading non-Java resources from classpath in
> JUnit tests
>
> Where is your resource file located in your source code tree?
>
> It should be under src/main/resources. I will assume it is under
> src/main/java -- that's your problem.
>
> Wayne
>
> On 5/13/07, Rossmanith, Philipp <ph...@t-systems.es>
wrote:
> >
> > Hi,
> > I have a component that is loading resources/files from the
classpath
> and for which I have written a JUnit test. However, when I run the
tests
> with Maven from the command line, they fail - obviously due to some
> classpath problems.*)
> > My assumption was that target/test-classes would form part of the
> classpath, which a test output with maven -X confirmed. **) The idea I
got
> was that once the resource file (here: a properties file) would be
found
> if it was contained in this folder. However, if I write out the
classpath
> programmatically from within the JUnit test, it doesn't contain the
> folder.***)
> > Please note that running the same test in Eclipse is working if I
add
> the test/resources folder as a source folder (with output in
target/test-
> classes).
> > Now my question is: How can I make add these non-Java resources to
the a
> Maven classpath? Is there a way to configure the classpath that Maven
is
> looking at via the POM?
> > Any help on this would be highly appreciated, as I already blew 2
days
> on this. I'm using Maven 2.0.6 and JUnit 3.8.1 unit tests.
> > Thanks in advance,
> > Ciao, Philipp
> > *) I get a NPE for an input stream i create via
> ClassLoader.getSystemResourceAsStream(this.filePath1).
> > **) From a file dump:
> > >>
> > [DEBUG] Adding to surefire test classpath: C:\Documents and
> Settings\9prossma\.m2\repository\org\codehaus\plexus\plexus-
> utils\1.1\plexus-utils-1.1.jar
> > [DEBUG] Test Classpath :
> > [DEBUG]   C:\Manchester\utilities\target\classes
> > [DEBUG]   C:\Manchester\utilities\target\test-classes
> > <<
> > ***) System.out.println("Class path: " +
> System.getProperty("java.class.path")):
> > >>
> > Class path: C:\Documents and
> Settings\9prossma\.m2\repository\org\apache\maven\surefire\surefire-
> api\2.0\surefire-api-2.0.jar;C:\Documents and
> Settings\9prossma\.m2\repository\org\codehaus\plexus\plexus-
> utils\1.1\plexus-utils-1.1.jar;C:\Doc
> > uments and
> Settings\9prossma\.m2\repository\org\apache\maven\surefire\surefire-
> booter\2.0\surefire-booter-2.0.jar
> > <<
> >
> > This e-mail may contain confidential or privileged information. Any
> unauthorised
> > copying, use or distribution of this information is strictly
prohibited.
> >
> >
---------------------------------------------------------------------
> > 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


This e-mail may contain confidential or privileged information. Any unauthorised
copying, use or distribution of this information is strictly prohibited.

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