Surefire and ClassLoading with URLS SystemClassLoader

2006-11-21 Thread Ryan Eccles
I've noticed a lot of discussion on ClassLoading with respect to 
resources, but little on loading classes themselves. Of the following 
tests, only the test useObjectClassLoader() works in surefire. In normal 
TestNG  both tests will pass. I've noticed a test using URLClassloader 
(ie plugin system loading jars) also fails with the same problem. Is 
there a different URL required for system classloader when running 
surefire?, or is there a configuration setting I need to get surefire to 
treat the URLs as it does at the command line? Thanks.


   @Test
   public void useObjectClassLoader() throws ClassNotFoundException {

   Class type = getClass().getClassLoader().loadClass(
   com.oculus.test.TestObject);
 // works
   Assert.assertEquals(type, TestObject.class);
   }

   @Test
   public void useSystemClassLoader() throws ClassNotFoundException {

   // thows exeception here
   Class type = ClassLoader.getSystemClassLoader().loadClass(
   com.oculus.test.TestObject);

   Assert.assertEquals(type, TestObject.class);
   }


Oh and TestObject is in the same package as the tests. Here is the 
exception:


java.lang.ClassNotFoundException: TestObject
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at com.oculus.test.Runner.useSystemClassLoader(Runner.java:20)



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Surefire and ClassLoading with URLS SystemClassLoader

2006-11-21 Thread JC Walmetz

Maybe you should try to play with the forkMode. See
http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#forkMode.
By default it is once, so a classloader is created for tests. Maybe with
never it would works. I have not tried that one.



Robert Harper-2 wrote:
 
 I've noticed a lot of discussion on ClassLoading with respect to 
 resources, but little on loading classes themselves. Of the following 
 tests, only the test useObjectClassLoader() works in surefire. In normal 
 TestNG  both tests will pass. I've noticed a test using URLClassloader 
 (ie plugin system loading jars) also fails with the same problem. Is 
 there a different URL required for system classloader when running 
 surefire?, or is there a configuration setting I need to get surefire to 
 treat the URLs as it does at the command line? Thanks.
 
 @Test
 public void useObjectClassLoader() throws ClassNotFoundException {
 
 Class type = getClass().getClassLoader().loadClass(
 com.oculus.test.TestObject);
   // works
 Assert.assertEquals(type, TestObject.class);
 }
 
 @Test
 public void useSystemClassLoader() throws ClassNotFoundException {
 
 // thows exeception here
 Class type = ClassLoader.getSystemClassLoader().loadClass(
 com.oculus.test.TestObject);
 
 Assert.assertEquals(type, TestObject.class);
 }
 
 
 Oh and TestObject is in the same package as the tests. Here is the 
 exception:
 
 java.lang.ClassNotFoundException: TestObject
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at com.oculus.test.Runner.useSystemClassLoader(Runner.java:20)
 
 
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Surefire-and-ClassLoading-with-URLS-SystemClassLoader-tf2679845s177.html#a7477728
Sent from the Maven - Users mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]