如何在构建时使用openJPA从单独的jar中增强类? [英] How to enhance a class from a separate jar at build time with openJPA?

查看:75
本文介绍了如何在构建时使用openJPA从单独的jar中增强类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用maven插件 openjpa-maven-plugin 增强来自另一个Jar的Entity类,但是不幸的是,我没有找到正确的方法.

I am trying to enhance an Entity class coming from another Jar using maven plugin openjpa-maven-plugin and unfortunately I didn't find a correct way to do it.

我有一个来自模块 MyDomain 的类 MyPojo ,该类包装在jar my-domain.jar 中:

I have one class MyPojo from module MyDomain packaged in jar my-domain.jar :

public class MyPojo {

private Long id;

...

}

在我的第二个项目 MyJpa 中,包装了 my-jpa.jar ,它依赖于模块 my-domain.jar ,并且配置了Maven结合使用Build Time OpenJPA Enhancer和以下工具:

In my second project MyJpa packaging my-jpa.jar, it depends on module my-domain.jar, and Maven is configured to use Build Time OpenJPA Enhancer with the following:

<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 :

and I am using an XML mapping orm.xml declared in persistence.xml :

            ... 
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>

    <mapping-file>META-INF/orm.xml</mapping-file>

 ...

以及如下所示的orm.xml:

and with the orm.xml that looks like :

    <entity class="MyPojo" access="FIELD">
    <table name="MYPOJO"/>
    <attributes>
        <id name="id">
            <generated-value strategy="AUTO"/>
        </id>
    </attributes>
    </entity>

运行 mvn install 会出现以下错误:

此配置不允许运行时优化,但是使用Javaagent在构建时或类加载时未增强以下列出的类型:

This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent:

当我将类 MyPojo 移到项目 MyJpa (而不是项目MyDomain)中时,它将起作用.

When I move the class MyPojo into the project MyJpa (instead of the project MyDomain), it works.

所以我的问题是:为了能够在构建时增强来​​自外部Jar的类 MyPojo ,我需要配置什么?

So my question is : what do I need to configure in order to be able to enhance at build time the class MyPojo coming from an external Jar ?

推荐答案

我需要配置什么才能在构建时增强来​​自外部Jar的MyPojo类?

what do I need to configure in order to be able to enhance at build time the class MyPojo coming from an external Jar ?

如果我正确理解了您的问题,那么您将无法在构建时增强位于jar中的类.如果您想以这种方式进行增强,则需要先解压缩该类,然后再进行增强.

If I understand your question correctly, you can't enhance a class that lives inside of a jar at build time. If you want to enhance in this way, you need to unjar the class, enhance, then rejar.

这篇关于如何在构建时使用openJPA从单独的jar中增强类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆