You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Michel Jung <mi...@gmail.com> on 2011/08/05 16:04:15 UTC
test-classes not used as classpath
Hi
My test-classes folder is not in the classpath - neither in eclipse, nor
when running the application with maven.
I created a new sample app, like this:
src/main/java/com/example/Main:
public static void main(final String[] args) {
System.out.println(Main.class.getResourceAsStream("/file.txt"));
}
And a file:
src/test/resources/file.txt
This was tested on two different computers with different eclipse
installations. The output is always the same: null.
What's wrong? I thought I already had such code working. It's also described
in
http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR
Thanks in advance.
Michel
Re: test-classes not used as classpath
Posted by Baptiste MATHUS <ml...@batmat.net>.
Hi,
This is expected behaviour.
Test-sources see main-sources, not the contrary, and it's a very good thing.
Compiled test-sources logically don't get packaged inside the resulting
archive (say jar, war...).
If you want a resources accessible from main-sources, put them inside
src/main/resources, not src/test/resources.
Cheers
2011/8/5 Michel Jung <mi...@gmail.com>
> Hi
>
> My test-classes folder is not in the classpath - neither in eclipse, nor
> when running the application with maven.
> I created a new sample app, like this:
>
> src/main/java/com/example/Main:
>
> public static void main(final String[] args) {
> System.out.println(Main.class.getResourceAsStream("/file.txt"));
> }
>
> And a file:
> src/test/resources/file.txt
>
> This was tested on two different computers with different eclipse
> installations. The output is always the same: null.
> What's wrong? I thought I already had such code working. It's also
> described
> in
>
> http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR
>
> Thanks in advance.
> Michel
>
--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !