FWIW, I have a trick that I use in my unit tests to retrieve
java.io.Filereferences to resources like that...the nice thing is that
it works both in
the IDE and from a Maven build.
private File getFile( String resourceName )
{
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
URL resource = cloader.getResource( resourceName );
if ( resource == null )
{
throw new IllegalArgumentException( "Could not get resource: " +
resourceName );
}
return new File( resource.getPath() );
}
Admittedly, I don't know that this is a bullet-proof way to get any
classpath resource as a file at any time, but for those two cases (during
testing in a Maven build, and from an IDE, where the resources are available
as a class folder) it works well for me.
HTH,
john
On 6/6/06, Lyndon Washington <[EMAIL PROTECTED]> wrote:
Hi Wendy,
Thanks for the information. I will try this out since it appears to be
what
I was looking for.
Cheers,
-Lyndon-
On 6/5/06, Wendy Smoak <[EMAIL PROTECTED]> wrote:
>
> On 6/5/06, Lyndon Washington <[EMAIL PROTECTED]> wrote:
>
> > I have a unit test that was setup in the old ANT build to load
resources
> > using a relative path. I have put the resource that is being
retrieved
> in
> > the projects 'test/resources/conf' folder. How would I reference the
> file,
> > where previously I used 'conf/foo.xml'?
> >
> > I guess I was assuming that there would be a system propery that I
could
> > use. Another snippet of info is that this project is part of a large
> pom
> > heirarchy, so the test could be run from the parent or from the actual
> > project location.
>
> http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html
>
> Surefire sets a 'basedir' system property, which you can retrieve with:
> System.getProperty("basedir")
>
> It also sets 'localRepository', which can be useful for locating
> artifacts (such as war files to deploy with Cargo.)
>
> In addition, you can pass in your own system properties in the
> <plugin>/<configuration> section.
>
> --
> Wendy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>