Just to follow up. Thanks for the feedback, it really helps for people to post things and say "What does this mean, what do I do next?" We very much appreciate it.

For this particular item, I've added some code to remove the stack trace and handle the situation with a clean log message giving a link to where you can get more information, such as:

INFO - Assembling app: /Users/dblevins/work/openejb3/itests/openejb- itests-app/target/openejb-itests-app-3.0.0-SNAPSHOT INFO - PersistenceUnit(name=cmp, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) ERROR - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested installation of a ClassFileTransformer which requires a JavaAgent. See http://openejb.apache.org/javaagent.html INFO - PersistenceUnit(name=openjpa-test-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) ERROR - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested installation of a ClassFileTransformer which requires a JavaAgent. See http://openejb.apache.org/javaagent.html

The javaagent.html will contain the information for setting this up in maven, ant, as well as when and why you might need the agent.

Again, thanks for the post. We do our best to put the feedback to good use!

-David


On Sep 25, 2007, at 1:05 AM, Gareth Evans wrote:

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.createContainer EntityManagerFactory(PersistenceProviderImpl.java:103) at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainer EntityManagerFactory(PersistenceProviderImpl.java:52) at org.apache.openejb.assembler.classic.PersistenceBuilder.createEntityMa nagerFactory(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.executeTest Set(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: [EMAIL PROTECTED]
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.




Reply via email to