Examples for gcloud-java (Java idiomatic client for Google Cloud Platform services).
- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
- [Examples] (http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/examples/package-summary.html)
Add this to your pom.xml file
<dependency>
<groupId>com.google.gcloud</groupId>
<artifactId>gcloud-java-examples</artifactId>
<version>0.0.10</version>
</dependency>To run examples from your command line:
-
Login using gcloud SDK (
gcloud auth loginin command line) -
Set your current project using
gcloud config set project PROJECT_ID -
Compile using Maven (
mvn compilein command line from your base project directory) -
Run an example using Maven from command line.
Here's an example run of DatastoreExample.
Note that you have to enable the Google Cloud Datastore API on the Google Developers Console before running the following commands.
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name add my\ comment"
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name display"
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name delete"
Here's an example run of StorageExample.
Before running the example, go to the Google Developers Console to ensure that Google Cloud Storage API is enabled and that you have a bucket. Also ensure that you have a test file (test.txt is chosen here) to upload to Cloud Storage stored locally on your machine.
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="upload /path/to/test.txt <bucket_name>"
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="list <bucket_name>"
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="download <bucket_name> test.txt"
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="delete <bucket_name> test.txt"
Java 7 or above is required for using this client.
This library follows [Semantic Versioning] (http://semver.org/).
It is currently in major version zero (0.y.z), which means that anything
may change at any time and the public API should not be considered
stable.
Contributions to this library are always welcome and highly encouraged.
See CONTRIBUTING for more information on how to get started.
Apache 2.0 - See LICENSE for more information.