tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gareth Evans <gar...@msoft.co.uk>
Subject Using openejb in unittest with maven2
Date Tue, 25 Sep 2007 08:05:17 GMT
Hi,

I've been having trouble using openejb from within a unittest with 
maven2.  I've managed to get this working from within eclipse and from 
the command line but when running from within maven2 the test fails with 
a classnotfoundexception.

java.lang.IllegalStateException: Unable to initialize agent
        at 
org.apache.openejb.javaagent.Agent.checkInitialization(Agent.java:70)
        at 
org.apache.openejb.javaagent.Agent.getInstrumentation(Agent.java:52)
        at 
org.apache.openejb.assembler.classic.Assembler$PersistenceClassLoaderHandlerImpl.addTransformer(Assembler.java:1007)
        at 
org.apache.openejb.persistence.PersistenceUnitInfoImpl.addTransformer(PersistenceUnitInfoImpl.java:234)
        at 
org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:103)
        at 
org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:52)
        at 
org.apache.openejb.assembler.classic.PersistenceBuilder.createEntityManagerFactory(PersistenceBuilder.java:159)
        at 
org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:421)
        at 
org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:299)
        at 
org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:207)
        at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:149)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:293)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:272)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.openejb.loader.OpenEJBInstance.init(OpenEJBInstance.java:36)
        at 
org.apache.openejb.client.LocalInitialContextFactory.init(LocalInitialContextFactory.java:59)
        at 
org.apache.openejb.client.LocalInitialContextFactory.getInitialContext(LocalInitialContextFactory.java:45)
        at 
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
        at 
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at 
com.msoft.project.OpenEjbWrapper.startOpenEjbServer(OpenEjbWrapper.java:43)
        at 
com.msoft.project.AbstractPersistenceTestCase.setUp(AbstractPersistenceTestCase.java:32)
        at junit.framework.TestCase.runBare(TestCase.java:128)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:120)
        at junit.framework.TestSuite.runTest(TestSuite.java:230)
        at junit.framework.TestSuite.run(TestSuite.java:225)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
        at 
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
        at 
org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
        at 
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)
Caused by: java.lang.ClassNotFoundException: 
org.apache.openejb.javaagent.Agent
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at 
org.apache.openejb.javaagent.Agent.checkInitialization(Agent.java:60)
        ... 46 more

At first i thought this was a classpath issue but i've checked using a 
mvn -X that the openejb-javaagent jar file is included in classpath.  
The code that appears to cause the problem is from 
org.apache.openejb.javaagent.Agent:

    ClassLoader systemCl = ClassLoader.getSystemClassLoader();
    Class<?> systemAgentClass = systemCl.loadClass(Agent.class.getName());

    Field instrumentationField = 
systemAgentClass.getDeclaredField("instrumentation");
    instrumentationField.setAccessible(true);
    instrumentation = (Instrumentation) instrumentationField.get(null);

The snippet appears to be looking for the Agent.class within the system 
classloader and i'm guessing that the maven-surefire-plugin uses its own 
classloader to run its tests.

Can anyone shed any light on this or is there a work around for this?

Regards,

Gareth

-- 
Gareth Evans

Senior Developer

MSoft eSolutions Limited
Technology Centre
Inward Way
Rossmore Business Park
Ellesmere Port
Cheshire
CH65 3EN

-- 
Tel:    +44 (0)870 0100 704
Fax:    +44 (0)870 9010 705
E-Mail: gareth@msoft.co.uk
Web:    www.msoft.co.uk

----------------------------------------------
Terms:
Please note that any prices quoted within this e-mail are subject to VAT.
All program details and code described in this e-mail are subject to
copyright © of MSoft eSolutions Limited and remain the intellectual
property of MSoft eSolutions Limited.
Any proposal or pricing information contained within this e-mail are
subject to MSoft eSolutions' Terms and Conditions
----------------------------------------------
Disclaimer:
This message is intended only for use of the addressee. If this message
was sent to you in error, please notify the sender and delete this
message. MSoft eSolutions Limited cannot accept responsibility for viruses,
so please scan attachments. Views expressed in this message do not
necessarily reflect those of MSoft eSolutions Limited who will not
necessarily be bound by its contents.



Mime
View raw message