title: Google Datastore Emulator using Java (Not using GAE)
body: <p>I am using Google Cloud's Datastore Client Library for Java to access the Cloud Datastore. </p>
  
  <p><strong>Note</strong>: I am not using App Engine to deploy my application; just running a local application for development purposes.</p>
  
  <p>Following the example, I can read/write to the Cloud Datastore.</p>
  
  <pre><code>Datastore datastore = DatastoreOptions.defaultInstance().service();
  KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
  Key key = keyFactory.newKey();
  Entity entity = datastore.get(key);
  </code></pre>
  
  <p>I want to be able to write to a local Datastore emulator instance instead.
  Following the guide <a href="https://cloud.google.com/datastore/docs/tools/datastore-emulator" rel="noreferrer">here</a>, I run <code>gcloud beta emulators datastore start</code>.
  This shows up in my terminal:</p>
  
  <pre><code>C:\Users\User&gt;gcloud beta emulators datastore start
  WARNING: Reusing existing data in [C:\Users\User\AppData\Roaming\gcloud\emulators\datastore].
  Executing: cmd /c C:\Users\User\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\cloud-datastore-emulator\cloud_datastore_emulator.cmd start --host=localhost --port=8964 --store_on_disk=True --consistency=0.9 --allow_remote_shutdown C:\Users\User\AppData\Roaming\gcloud\emulators\datastore
  [datastore] Oct 31, 2016 11:37:27 AM com.google.cloud.datastore.emulator.CloudDatastore$FakeDatastoreAction$7 apply
  [datastore] INFO: Provided --allow_remote_shutdown to start command which is no longer necessary.
  [datastore] Oct 31, 2016 11:37:27 AM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub &lt;init&gt;
  [datastore] INFO: Local Datastore initialized:
  [datastore]     Type: High Replication
  [datastore]     Storage: C:\Users\User\AppData\Roaming\gcloud\emulators\datastore\WEB-INF\appengine-generated\local_db.bin
  [datastore] Oct 31, 2016 11:37:28 AM io.grpc.internal.ManagedChannelImpl &lt;init&gt;
  [datastore] INFO: [ManagedChannelImpl@5e955596] Created with target localhost:8964
  [datastore] Oct 31, 2016 11:37:28 AM com.google.cloud.datastore.emulator.impl.LocalDatastoreFileStub load
  [datastore] INFO: The backing store, C:\Users\User\AppData\Roaming\gcloud\emulators\datastore\WEB-INF\appengine-generated\local_db.bin, does not exist. It will be created.
  [datastore] Oct 31, 2016 11:37:28 AM io.gapi.emulators.netty.NettyUtil applyJava7LongHostnameWorkaround
  [datastore] INFO: Unable to apply Java 7 long hostname workaround.
  [datastore] API endpoint: http://localhost:8964
  [datastore] If you are using a library that supports the DATASTORE_EMULATOR_HOST environment variable, run:
  [datastore]
  [datastore]   export DATASTORE_EMULATOR_HOST=localhost:8964
  [datastore]
  [datastore] Dev App Server is now running.
  [datastore]
  </code></pre>
  
  <p>I open another terminal and set the environment variables:</p>
  
  <pre><code>C:\Users\User&gt;gcloud beta emulators datastore env-init &gt; set_vars.cmd &amp;&amp; set_vars.cmd
  C:\Users\User&gt;set DATASTORE_DATASET=my-project-id
  C:\Users\User&gt;set DATASTORE_EMULATOR_HOST=localhost:8964
  C:\Users\User&gt;set DATASTORE_EMULATOR_HOST_PATH=localhost:8964/datastore
  C:\Users\User&gt;set DATASTORE_HOST=http://localhost:8964
  C:\Users\User&gt;set DATASTORE_PROJECT_ID=my-project-id
  </code></pre>
  
  <p>I run my application and make a REST call to post or retrieve an Entity, but this only reads/writes against the Cloud Datastore. Heading to <code>localhost:8964/datastore</code> gives me <code>Not Found</code>. Although starting the emulator tells me that it created <code>local_db.bin</code> file, the folder supposedly containing it is empty. 
  I also want to stay away from using LocalDatastoreHelper in order to access the local emulator. Is there any way to achieve using gcloud only ?</p>