You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by christophe blin <cb...@tennaxia.com> on 2006/07/04 11:06:56 UTC

[Maven2] test resources

Hi,

I am new to maven so excuse me if the questions have already been posted
(I do not find a related in the archives so I think it has not been so).

I am working with maven2 and hibernate.
My hibernate mapping is in /src/main/resources/META-INF :
mapping_common.hbm.xml

First question :
if I manually copy this file into /src/test/resources and I do (as
stated in the docs getting started) :
    InputStream is =
getClass().getResourceAsStream("mapping_common.hbm.xml");
    assert(is != null);
the assertion is thrown.

Am I doing something wrong or Should I configure something in the pom to
use src/test/resources as the resources directory for the unit tests ?

Second question :
I'd like to use the same mapping file when doing unit tests.
How can I configure the pom in order to perform a copy of the file just
before the execution of the test goal ?

Thanks and regards,
chris

-- 

_____________________________________________________________________
Tennaxia, www.tennaxia.com,
Pilotez vos obligations environnementales
_____________________________________________________________________
Siège social :
6, rue Léonard de Vinci - 53001 Laval Cedex -
Tél : 02 43 49 75 50 - Fax : 02 43 49 75 77
Agence Paris :
19, rue réaumur - 75003 Paris -
Tél : 01 42 77 04 19 - Fax : 08 25 19 19 61
Agence Lyon :
Parc du Chater - 63 rue de la garenne - 69340 FRANCHEVILLE -
Tél : 04 72 39 98 14 - Fax : 04 72 39 93 85
The information in this message sent by TENNAXIA is confidential 
and may be legally privileged. It is intended solely for the 
addressee(s). Access to this message by anyone else is unauthorized.
If you are not the intended recipient, please delete it and notify 
the sender : any disclosure, copying, distribution or any action 
taken or omitted to be taken in reliance on it, is prohibited and 
may be unlawful.



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


Re: [Maven2] test resources

Posted by christophe blin <cb...@tennaxia.com>.
thanks it works.

For a brief summary :
- having resources in src/main/resources make them available in the
classpath for the tests so you do not need any copy operation
- do not forget the leading "/" (which IMHO should be corrected in the docs)

regards,
chris

Hendrik Busch a écrit :
> Hi,
>
>>    try putting your mapping_common.hbm.xml on "src/main/resources/"
>> instead.
>>    or modify your getResourceAsStream to get the file
>> "META-INF/mapping_common.hbm.xml"
>
> you should not place Hibernate files in the META-INF directory. Either
> place them directly in src/main/resources (or src/test/resources if
> you only need them for testing) or place them in a folder
> corresponding to you Hibernate class package, e.g.
> src/main/resources/com/foo/bar.
>
> You should execute
>
> getClass().getResourceAsStream("/mapping_common.hbm.xml")
>
> with a leading slash in the path, as your previous path was relative
> the the package of the class in which you executed this command.
>

-- 

_____________________________________________________________________
Tennaxia, www.tennaxia.com,
Pilotez vos obligations environnementales
_____________________________________________________________________
Siège social :
6, rue Léonard de Vinci - 53001 Laval Cedex -
Tél : 02 43 49 75 50 - Fax : 02 43 49 75 77
Agence Paris :
19, rue réaumur - 75003 Paris -
Tél : 01 42 77 04 19 - Fax : 08 25 19 19 61
Agence Lyon :
Parc du Chater - 63 rue de la garenne - 69340 FRANCHEVILLE -
Tél : 04 72 39 98 14 - Fax : 04 72 39 93 85
The information in this message sent by TENNAXIA is confidential 
and may be legally privileged. It is intended solely for the 
addressee(s). Access to this message by anyone else is unauthorized.
If you are not the intended recipient, please delete it and notify 
the sender : any disclosure, copying, distribution or any action 
taken or omitted to be taken in reliance on it, is prohibited and 
may be unlawful.



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


Re: [Maven2] test resources

Posted by Hendrik Busch <he...@lexisnexis.de>.
Hi,

>    try putting your mapping_common.hbm.xml on "src/main/resources/" instead.
>    or modify your getResourceAsStream to get the file
> "META-INF/mapping_common.hbm.xml"

you should not place Hibernate files in the META-INF directory. Either 
place them directly in src/main/resources (or src/test/resources if you 
only need them for testing) or place them in a folder corresponding to 
you Hibernate class package, e.g. src/main/resources/com/foo/bar.

You should execute

getClass().getResourceAsStream("/mapping_common.hbm.xml")

with a leading slash in the path, as your previous path was relative the 
the package of the class in which you executed this command.

-- 
Mit freundlichen Grüßen / Kind regards

Hendrik Busch - Stellv. Leiter der Softwareentwicklung

LexisNexis Deutschland GmbH
http://www.lexisnexis.de
Feldstiege 100
D-48161 Münster
phone +49 (0) 2533-9300-455
fax +49 (0) 02533-9300-50
hendrik.busch@lexisnexis.de

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


Re: [Maven2] test resources

Posted by Pete Marvin King <la...@gmail.com>.
   try putting your mapping_common.hbm.xml on "src/main/resources/" instead.
   or modify your getResourceAsStream to get the file
"META-INF/mapping_common.hbm.xml"

   resources are searched on all the classpaths, normally META-INF is
added to the classpath
   so getClass().getResourceAsStream("mapping_common.hbm.xml") would
normally work
   if you're using a jar. But for your unit test it is not, only
target/classes is added to your classpath.
   you need to specify the directory it is in which is META-INF. 
correct me if i'm wrong. =)



christophe blin wrote:
> Hi,
>
> I am new to maven so excuse me if the questions have already been posted
> (I do not find a related in the archives so I think it has not been so).
>
> I am working with maven2 and hibernate.
> My hibernate mapping is in /src/main/resources/META-INF :
> mapping_common.hbm.xml
>
> First question :
> if I manually copy this file into /src/test/resources and I do (as
> stated in the docs getting started) :
>     InputStream is =
> getClass().getResourceAsStream("mapping_common.hbm.xml");
>     assert(is != null);
> the assertion is thrown.
>
> Am I doing something wrong or Should I configure something in the pom to
> use src/test/resources as the resources directory for the unit tests ?
>
> Second question :
> I'd like to use the same mapping file when doing unit tests.
> How can I configure the pom in order to perform a copy of the file just
> before the execution of the test goal ?
>
> Thanks and regards,
> chris
>
>   


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