Skip to content

Commit 7680281

Browse files
committed
Merge pull request #240 from ajkannan/usage-example
Add usage example for gcloud-java-examples
2 parents 89dafea + 494cd91 commit 7680281

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

gcloud-java-examples/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@ 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. Set your current project using `gcloud config set project PROJECT_ID`
28+
29+
3. Compile using Maven (`mvn compile` in command line from your base project directory)
30+
31+
4. Run an example using Maven from command line.
32+
33+
Here's an example run of `DatastoreExample`.
34+
35+
Note that you have to enable the Google Cloud Datastore API on the [Google Developers Console][developers-console] before running the following commands.
36+
```
37+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name add my\ comment"
38+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name display"
39+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample" -Dexec.args="my_name delete"
40+
```
41+
42+
Here's an example run of `StorageExample`.
43+
44+
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.
45+
```
46+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="upload /path/to/test.txt <bucket_name>"
47+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="list <bucket_name>"
48+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="download <bucket_name> test.txt"
49+
$mvn exec:java -Dexec.mainClass="com.google.gcloud.examples.StorageExample" -Dexec.args="delete <bucket_name> test.txt"
50+
```
51+
2352
Contributing
2453
------------
2554

@@ -50,3 +79,4 @@ Apache 2.0 - See [LICENSE] for more information.
5079
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
5180
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
5281
[cloud-platform]: https://cloud.google.com/
82+
[developers-console]:https://console.developers.google.com/

0 commit comments

Comments
 (0)