You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by David Garnier <ma...@davidgarnier.com> on 2004/06/21 22:23:20 UTC

Maven can't load resources from target dir

Hello,

It seems that Maven can't 'see' resources when they are in the target
dir. In the POM, I specified resources for the unit tests:

<resources>
 	<resource>
		<directory>${basedir}/target/res/</directory>
		<targetPath>/</targetPath>
		<includes>
			<include>**/*</include>
		</includes>
	</resource>
</resources>

This does not work. When I try to load a file using something like this
:
retval.getClass().getResourceAsStream("/netlist.txt");

I get a null InputStream. The resources are dynamically generated in a
post-goal on test:test-resources, but I've confirmed that the files are
indeed present.

Now here is the interesting part. If I generate the resources in
${basedir}/res instead of ${basedir}/target/res, maven:site will find
the files. I've set maven.junit.fork to true, otherwise Maven does not
find the files at all.

Is this a bug or a specified behavior?

Best Regards,
David Garnier
-- 



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


Re: Maven can't load resources from target dir

Posted by David Garnier <ma...@davidgarnier.com>.
Le mar 22/06/2004 à 02:17, Brett Porter a écrit :
> Is it possible that the resources arrive in target after the attempt
> to copy them as a resource?

Well I thought that Maven simply added the resources dir to the
classpath. But I couldn't find it in the classpath printed by the -X
option. But you're correct, the resources are not being copied to the
test-classes dir. I've changed the step that generated the resources
from a postGoal of test:test-resources to a preGoal, and now it works!
Thanks!

> I don't think keeping them in target is wise, regardless. If they are
> generated by the build, the build should put them in the right place
> to start with.

Well, the resources are generated by the build, and they are only used
by the tests, so from my point of view, target/res is the right dir.

Best Regards,

David


> - Brett
> 
> On Mon, 21 Jun 2004 22:23:20 +0200, David Garnier
> <ma...@davidgarnier.com> wrote:
> > 
> > Hello,
> > 
> > It seems that Maven can't 'see' resources when they are in the target
> > dir. In the POM, I specified resources for the unit tests:
> > 
> > <resources>
> >         <resource>
> >                 <directory>${basedir}/target/res/</directory>
> >                 <targetPath>/</targetPath>
> >                 <includes>
> >                         <include>**/*</include>
> >                 </includes>
> >         </resource>
> > </resources>
> > 
> > This does not work. When I try to load a file using something like this
> > :
> > retval.getClass().getResourceAsStream("/netlist.txt");
> > 
> > I get a null InputStream. The resources are dynamically generated in a
> > post-goal on test:test-resources, but I've confirmed that the files are
> > indeed present.
> > 
> > Now here is the interesting part. If I generate the resources in
> > ${basedir}/res instead of ${basedir}/target/res, maven:site will find
> > the files. I've set maven.junit.fork to true, otherwise Maven does not
> > find the files at all.
> > 
> > Is this a bug or a specified behavior?
> > 
> > Best Regards,
> > David Garnier
> > --
> > 
> > ---------------------------------------------------------------------
> > 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
-- 
David Garnier <da...@davidgarnier.com>
-- 



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


Re: Maven can't load resources from target dir

Posted by Brett Porter <br...@gmail.com>.
> > I don't think keeping them in target is wise, regardless. If they are
> > generated by the build, the build should put them in the right place
> > to start with.
> 
> Well, the resources are generated by the build, and they are only used
> by the tests, so from my point of view, target/res is the right dir.

What I mean is, you should probably generate them into
target/test-classes directly, rather than having the resources element
at all. I think this is less confusing.

BTW, I had to moderate your message onto the list - can you check you
are posting with the address you are subscribed with?

Thanks,
Brett

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


Re: Maven can't load resources from target dir

Posted by David Garnier <da...@davidgarnier.com>.
Le mar 22/06/2004 à 02:17, Brett Porter a écrit :
> Is it possible that the resources arrive in target after the attempt
> to copy them as a resource?

Well I thought that Maven simply added the resources dir to the
classpath. But I couldn't find it in the classpath printed by the -X
option. But you're correct, the resources are not being copied to the
test-classes dir. I've changed the step that generated the resources
from a postGoal of test:test-resources to a preGoal, and now it works!
Thanks!

> I don't think keeping them in target is wise, regardless. If they are
> generated by the build, the build should put them in the right place
> to start with.

Well, the resources are generated by the build, and they are only used
by the tests, so from my point of view, target/res is the right dir.

Best Regards,

David


> - Brett
> 
> On Mon, 21 Jun 2004 22:23:20 +0200, David Garnier
> <ma...@davidgarnier.com> wrote:
> > 
> > Hello,
> > 
> > It seems that Maven can't 'see' resources when they are in the target
> > dir. In the POM, I specified resources for the unit tests:
> > 
> > <resources>
> >         <resource>
> >                 <directory>${basedir}/target/res/</directory>
> >                 <targetPath>/</targetPath>
> >                 <includes>
> >                         <include>**/*</include>
> >                 </includes>
> >         </resource>
> > </resources>
> > 
> > This does not work. When I try to load a file using something like this
> > :
> > retval.getClass().getResourceAsStream("/netlist.txt");
> > 
> > I get a null InputStream. The resources are dynamically generated in a
> > post-goal on test:test-resources, but I've confirmed that the files are
> > indeed present.
> > 
> > Now here is the interesting part. If I generate the resources in
> > ${basedir}/res instead of ${basedir}/target/res, maven:site will find
> > the files. I've set maven.junit.fork to true, otherwise Maven does not
> > find the files at all.
> > 
> > Is this a bug or a specified behavior?
> > 
> > Best Regards,
> > David Garnier
> > --
> > 
> > ---------------------------------------------------------------------
> > 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
-- 
David Garnier <da...@davidgarnier.com>


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


Re: Maven can't load resources from target dir

Posted by Brett Porter <br...@gmail.com>.
Is it possible that the resources arrive in target after the attempt
to copy them as a resource?

I don't think keeping them in target is wise, regardless. If they are
generated by the build, the build should put them in the right place
to start with.

- Brett

On Mon, 21 Jun 2004 22:23:20 +0200, David Garnier
<ma...@davidgarnier.com> wrote:
> 
> Hello,
> 
> It seems that Maven can't 'see' resources when they are in the target
> dir. In the POM, I specified resources for the unit tests:
> 
> <resources>
>         <resource>
>                 <directory>${basedir}/target/res/</directory>
>                 <targetPath>/</targetPath>
>                 <includes>
>                         <include>**/*</include>
>                 </includes>
>         </resource>
> </resources>
> 
> This does not work. When I try to load a file using something like this
> :
> retval.getClass().getResourceAsStream("/netlist.txt");
> 
> I get a null InputStream. The resources are dynamically generated in a
> post-goal on test:test-resources, but I've confirmed that the files are
> indeed present.
> 
> Now here is the interesting part. If I generate the resources in
> ${basedir}/res instead of ${basedir}/target/res, maven:site will find
> the files. I've set maven.junit.fork to true, otherwise Maven does not
> find the files at all.
> 
> Is this a bug or a specified behavior?
> 
> Best Regards,
> David Garnier
> --
> 
> ---------------------------------------------------------------------
> 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