Im new with appengine, Im using appengine version 1.8.7(also happens to me in 1.8.6), and trying to add maven to the project.
When I persist an entity the log is the following:
[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.
My issue is that the local_db.bin is not created. And for example if I try to make a search of my peristed entity an errors appears.
[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)
...
This is my entity class:
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;
}
}
Here is 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>
In addition, if this project is created with the appengine eclipse plugin, nothing of this happends and me code works fine.
Thanks in advance
In Android Studio or Gradle build system, you can use jvmFlags to overwrite default path. Add below code to build.gradle
appengine {
jvmFlags=['-Ddatastore.backing_store=../../../local_db.bin']
}
I have been using App Engine for a while, but recently converted a project to use Maven and the Maven plugin. I had a very similar issue - it appears creating a local_db.bin file is not part of the start-up actions.
However, when I tried to read from the datastore, a log message indicated that since no local_db.bin was found, that one would be created (sorry, I don't have the exact log message handy). I was able to use the application normally after that, the local_db was indeed created.
However, I noticed that it was creating the local_db.bin file in the target
directory, not in the src
directory, so each time I re-started my server the local_db.bin file gets wiped out and has to be re-created. So, once local_db.bin
gets created, you can find it in the target/your_SNAPSHOT/WEB-INF/appengine-generated
and copy it into your src/main/webapp/WEB-INF/appengine-generated
dirctory. It should then get included in your target
directory when you do a build.
Please note that this has some drawbacks - any data changes you make in future sessions aren't persisted as they are stored in the local_db.bin that gets wiped out each build, but you can at least get a base of data to use. Hopefully I (or someone else here) can find a better way to get this to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With