Skip to content

Commit eac140a

Browse files
author
Ajay Kannan
committed
Add usage example for gcloud-java-examples
1 parent f7d30a6 commit eac140a

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

gcloud-java-examples/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,33 @@ Add this to your pom.xml file
2020
</dependency>
2121
```
2222

23+
To run examples from your command line:
24+
25+
1. Login using gcloud SDK (`gcloud auth login` in command line)
26+
27+
2. Compile using Maven (`mvn compile` in command line from your base project directory)
28+
29+
3. Run an example using Maven from command line.
30+
31+
Here's an example run of `DatastoreExample`.
32+
33+
Note that you have to enable the Google Cloud Datastore API on the [Google Developers Console][developers-console] before running the following commands.
34+
```
35+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="[<project_id>] [user] add my\ comment"
36+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="[<project_id>] [user] display"
37+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="[<project_id>] [user] delete"
38+
```
39+
40+
Here's an example run of `StorageExample`.
41+
42+
Before running the example, go to the [Google Developers Console][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.
43+
```
44+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="<project_id> upload /path/to/test.txt <bucket_name>"
45+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="<project_id> list <bucket_name>"
46+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="<project_id> download <bucket_name> test.txt"
47+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="<project_id> delete <bucket_name> test.txt"
48+
```
49+
2350
Contributing
2451
------------
2552

@@ -50,3 +77,4 @@ Apache 2.0 - See [LICENSE] for more information.
5077
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
5178
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
5279
[cloud-platform]: https://cloud.google.com/
80+
[developers-console]:https://console.developers.google.com/

0 commit comments

Comments
 (0)