【发布时间】:2015-08-26 14:37:32
【问题描述】:
我正在尝试使用 maven 插件 openjpa-maven-plugin 增强来自另一个 Jar 的 Entity 类,不幸的是我没有找到正确的方法。
我有一个类 MyPojo 来自模块 MyDomain 打包在 jar my-domain.jar 中:
public class MyPojo {
private Long id;
...
}
在我的第二个项目MyJpa 打包my-jpa.jar 中,它依赖于模块my-domain.jar,并且Maven 被配置为使用Build Time OpenJPA Enhancer,并具有以下功能:
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<configuration>
<includes>**/entity/*.class</includes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</plugin>
我正在使用在 persistence.xml 中声明的 XML 映射 orm.xml:
...
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<mapping-file>META-INF/orm.xml</mapping-file>
...
并使用看起来像的 orm.xml:
<entity class="MyPojo" access="FIELD">
<table name="MYPOJO"/>
<attributes>
<id name="id">
<generated-value strategy="AUTO"/>
</id>
</attributes>
</entity>
运行mvn install 会出现以下错误:
此配置不允许运行时优化,但以下列出的类型在构建时或类加载时未使用 javaagent 增强:
当我将类 MyPojo 移动到项目 MyJpa(而不是项目 MyDomain)中时,它可以工作。
所以我的问题是:我需要配置什么才能在构建时增强来自外部 Jar 的类 MyPojo?
【问题讨论】:
标签: maven jpa openjpa openjpa-maven-plugin