Hi basically don't mix enhancing. If you enhance at build time no need of the javaagent.
*1st case: build time enhancing through the mvn plugin* it works as described but only on exploded jars (in target/classes or target/test-classes typically) so no way to use it in your case *2nd case: javaagent* should work if correctly set on the jvm running the test (take care in surefire case, tests needs to be forked at least once to take into account this parameter) Side note: there is another case for not embedded runs which is experimental which does the enhancing at deploy time but it doesn't match your case i think *Romain Manni-Bucau* *Twitter: @rmannibucau <https://twitter.com/rmannibucau>* *Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau* *Github: https://github.com/rmannibucau* 2013/6/7 Reinis Vicups <[email protected]> > Hi everyone, > > after the heaty discussion between two senior openejb commiters on irc I > am totally confused and am begging for your help, dear community. > > Up to now my (wrong) understanding about OpenJPA enhancement was this: > > So that your maven tests work do following: > 1. enhance your @Entities with org.apache.openjpa:openjpa-**maven-plugin > in process-test-classes phase; > 2. make org.apache.openejb:openejb-**javaagent available to > surefire/failsafe plugins by copying javaagent jar to > ${project.build.directory} > 3. provide javaagent as argument when running surefire/failsafe plugins > like this: > > <plugin> > <groupId>org.apache.maven.**plugins</groupId> > <artifactId>maven-surefire-**plugin</artifactId> > <version>2.13</version> > <configuration> > <argLine>-javaagent:${project.**build.directory}/openejb-** > javaagent-${openejb.version}.**jar</argLine> > <workingDirectory>${project.**build.directory}</**workingDirectory> > </configuration> > </plugin> > > That's it, now this should work (and it works for me for the most of > scenarios). > > Now I have new scenario: I want to test my worker (built as a worker.jar > to be later packaged in an worker-ear.ear together with all the > dependencies to be deployed into openejb standalone container). This worker > depends on entities.jar (built as entities.jar) that contains classes for > @Entities and orm.xml that lists those classes like this: > > <entity-mappings> > <mapped-superclass class="my.AbstractBaseEntity" /> > <entity class="my.Permission" /> > </entity-mappings> > > This way I have to provide only persistence.xml within META-INF of my > worker.jar. This persistence.xml reffers orm.xml like this: > > <mapping-file>META-INF/orm.**xml</mapping-file> > <jar-file>entities.jar</jar-**file> > > When launching maven this leads to: Failed to execute goal > org.apache.openjpa:openjpa-**maven-plugin:2.2.0:test-**enhance (enhancer) > on project worker: Execution enhancer of goal org.apache.openjpa:openjpa-* > *maven-plugin:2.2.0:test-**enhance failed: org.apache.openjpa.** > persistence.**PersistenceProductDerivation:**java.lang.**IllegalArgumentException: > The jar resource "entities.jar" cannot be loaded. -> [Help 1] > > Ah ok, so it does not sees entities.jar (since they are not being copied > since worker itself is jar). > > So I add to worker.pom following > > <plugin> > <groupId>org.apache.maven.**plugins</groupId> > <artifactId>maven-dependency-**plugin</artifactId> > <version>2.7</version> > <executions> > <execution> > <id>copy</id> > <phase>process-resources</**phase> > <goals> > <goal>copy</goal> > </goals> > <configuration> > <useBaseVersion>true</**useBaseVersion> > <artifactItems> > <artifactItem> > <groupId>my</groupId> > <artifactId>entities</**artifactId> > <version>1.0.0-SNAPSHOT</**version> > <outputDirectory>${project.**build.directory}/test-classes<** > /outputDirectory> > </artifactItem> > </artifactItems> > </configuration> > </execution> > </executions> > </plugin> > > And get this: Failed to execute goal org.apache.openjpa:openjpa-** > maven-plugin:2.2.0:test-**enhance (enhancer) on project worker: Execution > enhancer of goal > org.apache.openjpa:openjpa-**maven-plugin:2.2.0:test-**enhance > failed: java.io.FileNotFoundException: file:\pathtomy\.m2\repository\** > my\entities\1.0.0-SNAPSHOT\**entities-1.0.0-SNAPSHOT.jar!\**my\Permission.class > (The filename, directory name or volume label syntax is incorrect) -> [Help > 1] > > Apparently it found the entities.jar, but now is unable to find entity > Permission in entities.jar (because it requires jar to be unpacked?). > > Well, I am out of ideas and would be happy if someone could hint me on how > to correctly configure maven so that my testcases get enhanced entities > from entities.jar > > Thank you very much, guys, > Reinis >
