10

Mavenプラグインを使用して別のJarからのEntityクラスを強化しようとしてopenjpa-maven-pluginいますが、残念ながら正しい方法が見つかりませんでした。

jar にパッケージ化されたMyPojoモジュールのクラスが 1 つあります。MyDomainmy-domain.jar

public class MyPojo {

private Long id;

...

}

私の 2 番目のプロジェクトMyJpaパッケージングmy-jpa.jarでは、それは module に依存し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>

orm.xmlで宣言された XML マッピングを使用していますpersistence.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 を使用して拡張されませんでした。

クラスMyPojoMyJpa(プロジェクト MyDomain ではなく) プロジェクトに移動すると、機能します。

MyPojo私の質問は次のとおりです。ビルド時に外部 Jar からのクラスを拡張できるようにするには、何を構成する必要がありますか?

4

1 に答える 1

4

what do I need to configure in order to be able to enhance at build time the class MyPojo coming from an external 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.

于 2015-08-31T15:14:56.650 に答える