[ http://jira.codehaus.org/browse/MSUREFIRE-115?page=comments#action_77008 ] Kenney Westerhof commented on MSUREFIRE-115: --------------------------------------------
Taking another look at the unit test, the line to read the resource should be URL dateResource = getClass().getClassLoader().getResource( "java/util/Date.betwixt" ); and not URL dateResource = Date.class.getResource( "/java/util/Date.betwixt" ); // or getResource("Date.betwixt"); Anyway, the Date.class.getResource(..) scheme only works with a flat classloader: all the resources should be in the boot classpath (like java -classpath target/test-classes/:target/classes etc..). In any classloading scheme where application resources are NOT in the boot/system classloader something like this will not work, unless you add the Date.betwixt file to the JRE's rt.jar. Since there are a lot of legacy apps out there that wrongly assume that everything is available in the system classloader, we could modify the forked mode to use that. It'll still use the 2 classloader approach, where surefire is in a separate child classloader, but everything else will be in the app classloader. Child delegation won't work, since the Date.class classloader doesn't recognize that option. It would require a major, probably breaking change, since the test classpath cannot be specified in the property file passed to the forked instance, but has to be specified on the commandline. This can break execution because the classpath will easily get too long to fit on a commandline. > Classloading problem for getting a resource > ------------------------------------------- > > Key: MSUREFIRE-115 > URL: http://jira.codehaus.org/browse/MSUREFIRE-115 > Project: Maven 2.x Surefire Plugin > Issue Type: Bug > Affects Versions: 2.2, 2.1.3 > Environment: Maven 2.0.4 > Windows XP > Reporter: Wim Deblauwe > Priority: Blocker > Fix For: 2.3 > > Attachments: surefire-test.zip, workaround-for-fork.zip > > > We are using Betwixt and some of our unit tests fail when run using > surefire, but run fine in IntelliJ or Maven 1. Betwixt looks for > descriptors with the name of the class + .betwixt to control how > something is written out in XML. It uses the construct: > myClass.getResource() to find the .betwixt file. > E.g. com.mycomp.MyClass -> com/mycomp/MyClass.betwixt > We have a betwixt file for the java.util.Date class. However, betwixt > seems to be unable to pick it up when using surefire. I have created a > small test that shows the problem and have attached it. > I tried with version 2.2 using different configurations (never, once, > pertest) and with version 2.1.3 (default configuration) -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira