We are anxiously awaiting OpenJPA to finish it's unenhanced support
so we can do CMP and JPA without a java agent. Until then, include a
chunk like this in your pom and you should be good to go. It's a lot
of tags, but it's essentially just doing two things: copy the agent
jar from the repo to your build dir; include the java agent when
surefire runs tests.
Definitely something we need to get up on the website documented.
Thanks for the reminder!
-David
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-javaagent</artifactId>
<version>3.0.0-SNAPSHOT</version>
<outputDirectory>${project.build.directory}</
outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>pertest</forkMode>
<!-- DEBUG: Uncomment this line and comment out the next -->
<!--<argLine>-Xdebug -Xnoagent -Djava.compiler=NONE -
Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 -
javaagent:${project.build.directory}/openejb-javaagent-3.0.0-
SNAPSHOT.jar=foo=bar</argLine>-->
<argLine>-javaagent:${project.build.directory}/openejb-
javaagent-3.0.0-SNAPSHOT.jar=foo=bar</argLine>
<systemProperties>
<property>
<name>openejb.home</name>
<value>${project.build.directory}/test-classes</value>
</property>
</systemProperties>
<basedir>${project.build.directory}</basedir>
</configuration>
</plugin>
</plugins>
</build>
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.