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]
