Reinis, I had a similar problem where I had some dependency jar with entities that I wanted enhancing. I would get the same error where it couldn't pull out the entity class from within the jar.
I pretty much settled on the fact that its just not possible to enhance class from your dependency jars. So what I do, is make sure that the my dependency jars that contain any entities are already enhanced and packaged within the jar (at build time). So this entities.jar you have, you must have a project for this? if so, just enhance them at that project. you shouldn't need a javagent, just enhance at build time. Chris Christo --- Twitter: https://twitter.com/ChrisChristo7 Tumblr: http://chrischristo7.tumblr.com LinkedIn: http://uk.linkedin.com/in/chrischristo GitHub: https://github.com/ChrisChristo On 7 Jun 2013, at 14:43, Reinis Vicups <[email protected]> wrote: > 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
