- Absolute pathnames, beginning with "/" are fully qualified file names
within the jar file.
- Relative pathnames, not beginning with "/" are relative to the class upon
which getResourceAsStream is called...."

Maybe try the getClass().getClassLoader().getResourceAsStream() method with
a relative path?


Patrick

On 9/26/07, James Depaul <[EMAIL PROTECTED]> wrote:
>
> Sorry, I must be dense, but I do not understand how that thread helps
> me... I've tried this code:
>
> InputStream xml = getClass().getClassLoader().getResourceAsStream("/data/"
> + fileName);
> return new FlatXmlDataSet(xml);
>
> But now Eclipse cannot find the files... and neither can Maven.
>
> My original data xml files are under CodsWebTesting/test/data directory. I
> use maven to copy them into 'target\test-classes\data' directory - but maven
> is not finding it there when I run mvn test... There's not much I can do
> abut the structure of the CodsWebTesting project at this point...
>
> How could I convince maven to look for these XML files in
> /target/test-classes/data dir or some other dir under /target ?
>
> Thanks,
> James
>
>
>
>
> [image: Inactive hide details for "Wayne Fay" <[EMAIL PROTECTED]>]"Wayne
> Fay" <[EMAIL PROTECTED]>
>
>
>
>     *"Wayne Fay" <[EMAIL PROTECTED]>*
>
>             09/26/2007 02:47 PM Please respond to
>             "Maven Users List" <[email protected]>
>
>
> To
>
> "Maven Users List" <[email protected]>
> cc
>
>
> Subject
>
> Re: Resource relative paths in test cases...
>
> This comes up pretty frequently. In the future, try searching the
> archives first...
>
> Here's a search query with a few hits from the last 3 mos:
>
> http://www.nabble.com/forum/Search.jtp?query=classloader+getclass&local=y&forum=178&daterange=4&startdate=&enddate=
>
> Wayne
>
> On 9/26/07, Insitu <[EMAIL PROTECTED]> wrote:
> > James Depaul <[EMAIL PROTECTED]> writes:
> >
> > > Hello -
> > >
> > > I'm working on maven-izing a project that's composed of three modules.
>  I
> > > have the POMs configured with proper dependencies.  Compile all works
> now
> > > and now I'm tying to execute the Test Cases and have some problems -
> it has
> > > to do with how Maven resolves the resource locations...
> > >
> > > The test cases are using DBUNIT framework to insert data into the db
> before
> > > running.  Inside the getDataSet() method in test case I need to create
> an
> > > InputStream to the XML file that contains the test data for the run.
>  The
> > > code implementation that I have that works perfectly in Eclipse is
> this:
> > >
> > >     protected IDataSet getDataSet() throws Exception {
> > >         String fileName = "cods_user_auth-seed.xml"; // data file
> > >         URL rootPath = UserAdminUserTest.class.getResource("/data/" +
> > > fileName);   // root path location + specific location of the file
> > >         System.out.println("rootPath=" + rootPath);
> > >         return new FlatXmlDataSet(
> > >                 new FileInputStream(rootPath.getFile())); // get the
> file
> > > as InputStream
> > >     }
> > >
> >
> > This assumes  "cods_user_auth-seed.xml" is located at
> > "src/test/resources":
> >
> >     InputStream xml =
> >     getClass().getClassLoader().getResourceAsStream("/data/" +
> >       fileName);
> >     return new FlatXmlDataSet(xml);
> >
> > HTH
> > --
> > OQube < software engineering \ génie logiciel >
> > Arnaud Bailly, Dr.
> > \web> http://www.oqube.com
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>

Reply via email to