1

尝试使用我的代码启动 appengine 开发服务器时出现此错误:

(命令是appengine-java-sdk-1.8.1.1/bin/dev_appserver.sh target/myapp/)

信息:捕获并报告了异常。消息:org.datanucleus.exceptions.ClassNotResolvedException:在 CLASSPATH 中找不到类“com.google.appengine.datanucleus.DatastoreManager”。请检查您的规范和您的 CLASSPATH。javax.jdo.JDOFatalInternalException:在 CLASSPATH 中找不到类“com.google.appengine.datanucleus.DatastoreManager”。请检查您的规范和您的 CLASSPATH。

我正在使用 Guice,所以我的模块如下所示:

public class MyModule extends ServletModule {

@Override
public void configureServlets() {
  bind(PersistenceManagerFactory.class)
      .toInstance(JDOHelper.getPersistenceManagerFactory("transactions-optional"));
  // ...

在我的代码的其他地方,我注入了 PersistenceManagerFactory 并定义了一些简单的持久性注释,现在这是我迄今为止对 JDO 的唯一引用。

我的 WEB-INF/jdoconfig.xml 几乎是来自 appengine 页面的精确复制/粘贴:

<?xml version="1.0" encoding="utf-8"?>
<jdoconfig 
    xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig">

  <persistence-manager-factory name="transactions-optional">
    <property name="javax.jdo.PersistenceManagerFactoryClass"
        value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
    <property name="javax.jdo.option.ConnectionURL" value="appengine" />
    <property name="javax.jdo.option.NontransactionalRead" value="true" />
    <property name="javax.jdo.option.NontransactionalWrite" value="true" />
    <property name="javax.jdo.option.RetainValues" value="true" />
    <property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true" />
    <property name="datanucleus.appengine.singletonPMFForName" value="true" />
  </persistence-manager-factory>
</jdoconfig>

DatastoreManager 应该在类路径上,但我怀疑我的依赖项可能有问题。我的 maven pom 文件依赖项如下所示:

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <com.google.inject.version>3.0</com.google.inject.version>
    <com.sun.jersey.version>1.17.1</com.sun.jersey.version>
    <org.codehaus.jackson.version>1.9.12</org.codehaus.jackson.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.google.appengine.orm</groupId>
      <artifactId>datanucleus-appengine</artifactId>
      <version>2.1.2</version>
    </dependency>

    <dependency>
      <groupId>com.google.appengine</groupId>
      <artifactId>appengine-api-labs</artifactId>
      <version>1.8.1.1</version>
    </dependency>

    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>14.0.1</version>
    </dependency>

    <dependency>
      <groupId>com.google.inject</groupId>
      <artifactId>guice</artifactId>
      <version>${com.google.inject.version}</version>
    </dependency>

    <dependency>
      <groupId>com.google.inject.extensions</groupId>
      <artifactId>guice-servlet</artifactId>
      <version>${com.google.inject.version}</version>
    </dependency>

    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-json</artifactId>
      <version>${com.sun.jersey.version}</version>
    </dependency>

    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-server</artifactId>
      <version>${com.sun.jersey.version}</version>
    </dependency>

    <dependency>
      <groupId>com.sun.jersey.contribs</groupId>
      <artifactId>jersey-guice</artifactId>
      <version>${com.sun.jersey.version}</version>
    </dependency>

    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.6</version>
    </dependency>

    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-core-asl</artifactId>
      <version>${org.codehaus.jackson.version}</version>
    </dependency>

    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-jaxrs</artifactId>
      <version>${org.codehaus.jackson.version}</version>
    </dependency>

    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>${org.codehaus.jackson.version}</version>
    </dependency>

    <dependency>
      <groupId>org.datanucleus</groupId>
      <artifactId>datanucleus-api-jdo</artifactId>
      <version>[3.2.0, 3.2.99)</version>
    </dependency>

    <dependency>
      <groupId>org.datanucleus</groupId>
      <artifactId>datanucleus-core</artifactId>
      <version>[3.2.0, 3.2.99)</version>
      <scope>runtime</scope>
    </dependency>

    <dependency>
      <groupId>org.datanucleus</groupId>
      <artifactId>datanucleus-jdo-query</artifactId>
      <version>3.0.2</version>
    </dependency>

    <dependency>
      <groupId>javax.cache</groupId>
      <artifactId>cache-api</artifactId>
      <version>0.61</version>
    </dependency>

    <dependency>
      <groupId>javax.jdo</groupId>
      <artifactId>jdo-api</artifactId>
      <version>3.0.1</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.2</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.5</version>
    </dependency>

    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.0.13</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>${project.artifactId}</finalName>

    <plugins>
      <plugin>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-maven-plugin</artifactId>
        <version>3.2.0-release</version>
        <configuration>
          <api>JDO</api>
          <props>${basedir}/datanucleus.properties</props>
<!--           <log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration> -->
          <verbose>true</verbose>
        </configuration>
        <executions>
          <execution>
            <phase>process-classes</phase>
            <goals>
              <goal>enhance</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

我确信我错过了一些明显的错误,但作为 appengine 和 JDO 的新手,我现在迷路了。

4

0 回答 0