[ http://jira.codehaus.org/browse/MSUREFIRE-115?page=comments#action_79526 ] Christian Schulte commented on MSUREFIRE-115: ---------------------------------------------
I have similar problems (since more than a year!) but with the JDKs service provider lookup mechanism. At least Sun JDKs will lookup service provider files (META-INF/services) for charactersets by using the system classloader. This class loader can never have a reference to some artifact provided by surefire since it cannot be modified. Currently the surefire plugin documentation states: By default, Surefire loads classes using the default Java mechanism. However, it can be set to use "child first" classloading, like a web application - meaning your dependencies take precedence over those in the JDK. Classes in the java.* and javax.* packages can never be overridden. The only use for this is so that code in the test classpath can override stuff present in the JDK or its "standard extensions" directory which is not in these restricted packages. This means effectively implementations of the various "service provider" interfaces in java such as the xml parser implementation used by jaxp, the cryptography providers, the socket implementation class. This holds true as long as the JDK lookup mechanism for service provider files uses the context class loader. Sun JDKs do not! At least not for charactersets. They always use the system classloader. I really need a solution to enable the system class loader (e.g. pass the artifacts to the system classpath when forking via the -classpath argument). I attached two patches to this issue which will introduce a new maven-surefire-plugin parameter named useSystemClassLoader which will be set to false by default. When set to true the commandline classpath build by SurefireBooter will also contain all classpath elements from the maven plugin. Really. I had to disable unit tests for a project for more than a year now! There must be a way to enable the system classloader for JDKs which uses it for service provider lookups. > 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-2.0-UseSystemClassLoader.patch, > 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