Reputation: 26251
I'm developing App Engine application in Android Studio and testing it on my local machine (with local datastore). It's Java based app. Every time I re-run the server the local datastore is cleared. I've found several solutions for Python developers but it looks like there's no answer for Java.
Android Studio allows only to change:
I've tried with VM args but these are for Java VM not for the app server obviously. Is there a way to persist local datastore across server restarts? It would be perfect If I could run this configuration directly from Android Studio.
Upvotes: 10
Views: 2076
Reputation: 278
The local datastore gets cleared because it is by default located in the application exploded war directory (which is deleted in its entirety on every build).
Instead of having to running the dev server manually from a terminal, you can actually just add a VM arg to the appengine run configuration to locate the datastore in another location:
-Ddatastore.backing_store="/path/to/datastore/file/location/local_db.bin"
(Solution found on: https://code.google.com/p/android/issues/detail?id=68225)
Upvotes: 17
Reputation: 2092
Like Arjan says, you can use -Ddatastore.backing_store
.
If you use Android Studio 1.5, modify build.gradle
. On appengine
put the paramater jvmFlags
. Example:
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
jvmFlags = ["-Ddatastore.backing_store=\"D:/temp/local_db.bin\""]
}
Upvotes: 9
Reputation: 26251
After several hours of searching I've finally found how to use user defined file as a local storage. Unfortunately it doesn't work directly from Android Studio, servers must be run from the terminal.
Here are arguments for Java's dev-appserver:
Usage: <dev-appserver> [options] <app directory>
Options:
--help, -h Show this help message and exit.
--sdk_root=DIR Overrides where the SDK is located.
--server=SERVER The server to use to determine the latest
-s SERVER SDK version.
--address=ADDRESS The address of the interface on the local machine
-a ADDRESS to bind to (or 0.0.0.0 for all interfaces).
--port=PORT The port number to bind to on the local machine.
-p PORT
--disable_update_check Disable the check for newer SDK versions.
--generated_dir=DIR Set the directory where generated files are created.
--default_gcs_bucket=NAME Set the default Google Cloud Storage bucket name.
--jvm_flag=FLAG Pass FLAG as a JVM argument. May be repeated to
supply multiple flags.
You have to change generated_dir
argument. To run dev server directly from the terminal there's a very nice command:
/usr/lib/jvm/default-java/bin/java -javaagent:$HOME/.gradle/appengine-sdk/appengine-java-sdk-1.9.9/lib/agent/appengine-agent.jar -Xbootclasspath/p:$HOME/.gradle/appengine-sdk/appengine-java-sdk-1.9.9/lib/override/appengine-dev-jdk-overrides.jar -Didea.launcher.port=7533 -Didea.launcher.bin.path=/opt/android-studio/bin -Dfile.encoding=UTF-8 -classpath $HOME/.gradle/appengine-sdk/appengine-java-sdk-1.9.9/lib/appengine-tools-api.jar:/opt/android-studio/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain com.google.appengine.tools.development.DevAppServerMain --address=0.0.0.0 --port=8080 --generated_dir=$HOME/sandbox/ $HOME/app/backend/build/exploded-app
I've changed the generated_dir
argument to --generated_dir=$HOME/sandbox/
Please note you've to provide Android Studio path and App Engine SDK version. For my workstation it's /opt/android-studio
and appengine-java-sdk-1.9.9
accordingly.
Upvotes: 1