datanucleus工具如何对运行文件进行增强?

How the datanucleus tool to run the files for enhancement?

为了增强 类 并使正常 Java 类 “持久化”,我使用了 DataNucleus Enhancer。我遇到的问题是:运行 datanucleus 工具没有文件(错误日志如下所示),因此 datanucleus 没有增强 类。 datanucleus 运行 如何增强文件?

Pom.xml

datanucleus 的依赖关系

        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jdo</artifactId>
            <version>4.0.5</version>
           <!--<scope>compile</scope> -->
        </dependency>

        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>4.0.6</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-rdbms</artifactId>
            <version>4.0.9</version>
            <scope>runtime</scope>
        </dependency>

用于增强的 Datanucleus 插件

            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>datanucleus-maven-plugin</artifactId>
                <version>5.2.1</version>
                <configuration>
                    <api>JDO</api>
                    <persistenceUnitName>MyUnit_Example</persistenceUnitName> <!-- todo: change persistance name-->                   
                    <log4jConfiguration>${pom.basedir}/data/log4j.properties</log4jConfiguration>
                    <generateConstructor>true</generateConstructor>
                    <verbose>true</verbose>
                    <alwaysDetachable>true</alwaysDetachable>
                    <metadataIncludes>${pom.basedir}/dir_name_1/dir_name_2/model**/*.class</metadataIncludes>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

警告列表

[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for org.mortbay.jetty:servlet-api:jar:2.5-6.0.0beta12 is missing, no dependency information available
[INFO] 
[INFO] --- datanucleus-maven-plugin:5.2.1:enhance (default-cli) @ forsteinrichtung ---
[WARNING] No files to run DataNucleus tool 'org.datanucleus.enhancer.DataNucleusEnhancer'

我的增强设置 类,希望它能帮助您找到解决方案。您需要添加一个 persistence.xml,更新 Datanucleus 依赖工件版本并为 datanuclees 添加一个 javax.jdo 的依赖,它为 java 模型抽象提供接口以实现持久性。

pom.xml

Datanucleus 的依赖性

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-api-jdo</artifactId>
    <version>5.2.7</version>
    <scope>compile</scope>
</dependencies>

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>5.2.9</version>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-rdbms</artifactId>
    <version>5.2.9</version>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>javax.jdo</artifactId>
    <version>3.2.0-m11</version>
</dependency>

用于增强的 Datanucleus 插件

  <plugin>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-maven-plugin</artifactId>
        <version>5.2.1</version>
        <configuration>
            <api>JDO</api>
            <persistenceUnitName>h2</persistenceUnitName>
            <log4jConfiguration>${project.basedir}/data/config/log4j.properties</log4jConfiguration>
            <verbose>true</verbose>
            <fork>false</fork>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.datanucleus</groupId>
                <artifactId>datanucleus-core</artifactId>
                <version>5.2.9</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
        <executions>
            <execution>
                <phase>process-classes</phase>
                <goals>
                    <goal>enhance</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

persistence.xml

persistence.xml 的位置是“资源 > META-INF > persistence.xml”。如果 persistence.xml 不存在则需要创建新的 persistence.xml.

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
         version="2.0">
<persistence-unit name="h2" transaction-type="RESOURCE_LOCAL">
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
        <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.show_sql" value="true" />
        <property name="javax.persistence.schema-generation.database.action" value="create"/>
        <property name="javax.persistence.schema-generation.create-source" value="script"/>
        <property name="javax.persistence.schema-generation.create-script-source" value="sql/create.sql"/>
        <!--<property name="javax.persistence.schema-generation.drop-source" value="script"/> -->
        <!--<property name="javax.persistence.schema-generation.drop-script-source" value="sql/drop.sql"/> -->
        <property name="javax.persistence.sql-load-script-source" value="sql/initial_data.sql" />
        <property name="javax.persistence.jdbc.user" value="sa"/>
        <property name="javax.persistence.jdbc.password" value="sa"/>
    </properties>
</persistence-unit>