我是 appengine 的新手,我使用的是 appengine 版本 1.8.7(在 1.8.6 中也发生在我身上),并试图将 maven 添加到项目中。
当我坚持一个实体时,日志如下:
[INFO] nov 07, 2013 5:38:33 PM com.google.appengine.api.datastore.dev.LocalDatastoreService init
[INFO] INFO: Local Datastore initialized:
[INFO] Type: High Replication
[INFO] Storage: D:\Projects\JEE\myapp\tmp\local_db.bin
[INFO] nov 07, 2013 5:38:33 PM com.google.appengine.api.datastore.dev.LocalDatastoreService load
[INFO] INFO: The backing store, D:\Projects\JEE\myapp\tmp\local_db.bin, does not exist. It will be created.
我的问题是 local_db.bin 没有创建。例如,如果我尝试搜索我的持久实体,则会出现错误。
[INFO] java.lang.IllegalArgumentException: Type com.harriague.myapp.dao.entities.Travel is not a known entity type
[INFO] at org.datanucleus.api.jpa.metamodel.MetamodelImpl.entity(MetamodelImpl.java:193)
...
这是我的实体类:
package com.harriague.myapp.dao.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Column;
import com.google.appengine.api.datastore.Key;
@Entity(name = "Travel")
public class Travel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key travelId;
@Column(name = "name")
private String name;
public Travel() {
}
public Key getTravelId() {
return travelId;
}
public void setTravelId(Key travelId) {
this.travelId = travelId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
这是mi pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>com.harriague</groupId>
<artifactId>myapp</artifactId>
<properties>
<appengine.app.version>1</appengine.app.version>
<appengine.target.version>1.8.7</appengine.target.version>
<datanucleus-core.version>3.1.3</datanucleus-core.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>${appengine.target.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-endpoints</artifactId>
<version>${appengine.target.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-labs</artifactId>
<version>${appengine.target.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- JSON -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
<!-- Spring framework -->
<!--
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
-->
<!-- Javax persistence -->
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>${datanucleus-core.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jpa</artifactId>
<version>3.1.3</version>
</dependency>
<dependency>
<groupId>com.google.appengine.orm</groupId>
<artifactId>datanucleus-appengine</artifactId>
<version>2.1.2</version>
<!-- Need to exclude the enhancer since it interfere with the enhancer plugin. -->
<exclusions>
<exclusion>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-enhancer</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>2.5.1</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<!-- in order to interpolate version from pom into appengine-web.xml -->
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
<!--
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
-->
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
<configuration>
<enableJarClasses>false</enableJarClasses>
<!--<jvmFlags>
<jvmFlag>-Ddatastore.backing_store=${basedir}\local_db.bin</jvmFlag>
</jvmFlags>
-->
<jvmFlags>
<jvmFlag>-Dappengine.generated.dir=${basedir}/tmp</jvmFlag>
</jvmFlags>
<!--
<jvmFlags>
<jvmFlag>-Xdebug</jvmFlag>
<jvmFlag>-Xrunjdwp:transport=dt_socket,address=8080,server=y,suspend=y</jvmFlag>
</jvmFlags>
-->
<disableUpdateCheck>true</disableUpdateCheck>
</configuration>
</plugin>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<api>JPA</api>
<fork>false</fork>
<persistenceUnitName>transactions-optional</persistenceUnitName>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
此外,如果这个项目是使用 appengine eclipse 插件创建的,那么这一切都不会发生,我的代码可以正常工作。
提前致谢