gpt4 book ai didi

java - App Engine 不创建 local_db.bin

转载 作者:搜寻专家 更新时间:2023-10-31 19:55:40 26 4
gpt4 key购买 nike

我是 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 插件创建的,那么这一切都不会发生,我的代码也可以正常工作。

提前致谢

最佳答案

在 Android Studio 或 Gradle 构建系统中,您可以使用 jvmFlags 覆盖默认路径。添加以下代码到 build.gradle

appengine {
jvmFlags=['-Ddatastore.backing_store=../../../local_db.bin']
}

关于java - App Engine 不创建 local_db.bin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19846495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com