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

发布于 2025-01-09 04:40:02 字数 2990 浏览 0 评论 0原文

为了增强类并使普通 Java 类“持久化”,我使用了 DataNucleus 增强器。我遇到的问题是:没有文件可以运行 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'

For to enhance the classes and to make normal Java classes "persistable", I have used DataNucleus Enhancer. The issue I am having is: No files to run datanucleus tool (error log shown below) and because of that datanucleus is not enhancing the classes. How the datanucleus run the files for enhancement?

Pom.xml

Dependencies of 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 for enhance

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

Warning list

[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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千里故人稀 2025-01-16 04:40:02

我的增强课程设置,希望能帮助您找到解决方案。您需要添加 persistence.xml,更新 Datanucleus 依赖项工件版本,并为 datanuclues 添加 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 的位置是“resources > META-INF > ”。持久性.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>

My setup for enhance the classes, I hope it could help you to find a solution. You need to add a persistence.xml, update the Datanucleus dependency artifact versions and add a dependency of javax.jdo for datanuclues which provides an interface to java model abstraction for persistence.

pom.xml

Depandancy for 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 for enhance

  <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

The location for persistence.xml is "resources > META-INF > persistence.xml". If persistence.xml does not exist then one need to create new 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文