App Engine、JDO和Maven。启动时出现错误。

5

我正在尝试使用JDO和Maven配置创建一个简单的测试项目,与App Engine相关。

我的编译和数据增强步骤都成功了。但是在运行时(包括mvn:test和appengine:devserver),我遇到了以下问题:

1) Error in custom provider, javax.jdo.JDOFatalInternalException: 
Class "com.google.appengine.datanucleus.DatastoreManager" was not found in the CLASSPATH.
Please check your specification and your CLASSPATH.

然而,我的类路径(target/demo/WEB-INF/lib)确实包含:datanucleus-appengine-2.1.1.jar

而且我的依赖项与Google datanucleus项目的POM文件中指定的相同:

  <dependency>
    <groupId>javax.jdo</groupId>
    <artifactId>jdo-api</artifactId>
    <version>3.0.1</version>
  </dependency>
  <dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>[3.1.1, 3.2)</version>
    <scope>runtime</scope>
  </dependency>
  <dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-api-jdo</artifactId>
    <version>[3.1.1, 3.2)</version>
  </dependency>
  <dependency>
    <groupId>com.google.appengine.orm</groupId>
    <artifactId>datanucleus-appengine</artifactId>
    <version>2.1.1</version>
  </dependency>

希望能得到任何建议。

RB


可能会出现JDO版本与datanucleus冲突的情况。将datanucleus-core更改为3.0。 - Sabarish
@Sabarish,我尝试了许多版本组合。 从App Engine ORM项目引用的那些开始(即JDO:3.0.1、DataNucleus:[3.1.1,3.2)、ORM:2.1.1):https://code.google.com/p/datanucleus-appengine/source/browse/branches/2_1_1/pom.xml 在增强阶段早期似乎会出现JDO/datanucleus冲突。 - rsb
所以,这个链接似乎有正确的信息(从GAE文档中非常难找到):datanucleus-appengine 2.1.1需要org.datanucleus 3.1(插件也需要匹配)。然而,现在我遇到了一个不同的构建错误:“类“XXX”不可持久化。这意味着它要么还没有被增强,要么增强版本的文件不在CLASSPATH中。” (mvn datanuclues:enhance运行良好)。开始浏览冗长且到目前为止难以理解的日志文件... - rsb
2个回答

7
我现在已经让所有的东西都可以工作了。由于我花费了几天的时间来浏览这些内容,因此我想分享一些要点:

1). 所有版本都非常重要(尤其是将App Engine ORM 2.1.1与DataNucleus 3.1.1(包括插件)匹配)。

http://www.datanucleus.org/products/accessplatform_3_2/datastores/appengine.html

以下是我最终采用的版本:

  <dependency>
    <groupId>javax.jdo</groupId>
    <artifactId>jdo-api</artifactId>
    <version>3.0.1</version>
  </dependency>
  <dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-core</artifactId>
    <version>3.1.1</version>
    <scope>runtime</scope>
  </dependency>
  <dependency>
    <groupId>org.datanucleus</groupId>
    <artifactId>datanucleus-api-jdo</artifactId>
    <version>3.1.2</version>
  </dependency>
  <dependency>
    <groupId>com.google.appengine.orm</groupId>
    <artifactId>datanucleus-appengine</artifactId>
    <version>2.1.2</version>
  </dependency>

  ...

  <plugin>
    <groupId>org.datanucleus</groupId>
    <artifactId>maven-datanucleus-plugin</artifactId>
    <version>3.1.2</version>
    <configuration>
      <log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
      <verbose>false</verbose>
      <fork>false</fork>
    </configuration>
    <executions>
      <execution>
        <phase>process-classes</phase>
        <goals>
          <goal>enhance</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

2). 检查 datanucleus.log 的末尾,以确认您的类已通过 mvn datanucleus:enhance 进行增强。我最终意识到我的测试类(在 src/test 中)被忽略了。


1
http://code.google.com/p/datanucleus-appengine/wiki/Compatibility 定义了需要的版本,结合各种插件的Maven pom.xml;毕竟这就是pom.xml依赖关系的作用。 - Neil Stockton
@rsb:非常感谢您发布您的pom文件。我已经快要疯了,但这解决了我的问题。 - m09

0

我在pom.xml中添加了false,并且适用于我

<plugins>
            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>maven-datanucleus-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    **<fork>false</fork>**
                    <log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
                    <verbose>true</verbose>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接