Giter Club home page Giter Club logo

compute-getting-started-java's Introduction

compute-getting-started-java

This sample command line application demonstrates how to access the Google Compute Engine API using the Google Java API Client Library.

Products

Language

APIs

Setup Instructions

  1. Register your application with Google Cloud Console.
  2. Visit the Cloud Console
  3. If this is your first time then click "Create Project," otherwise you can reuse an existing project by click on it. 1. Note: You will need to enable billing for new projects by clicking on Compute Engine in the left hand navigation menu.
  4. Click on "APIs & auth" in the left hand navigation menu and then the "Registered Apps" subitem.
  5. Click on "Register App," enter "GCE Sample," as the name, choose the "Native" type and click the "Register," button.
  6. Expand the "OAuth 2.0 Client ID" section of the screen and download the JSON file using the button supplied. Later on you will copy this downloaded file to src/main/resources/client_secrets.json.
  7. Click "Overview" in the left hand navigation and copy your Project ID into into /src/main/java/com/google/api/services/samples/computeengine/cmdline/ComputeEngineSample.java so that the following line is updated. Not performing this step will result in an 400: Bad Request error; specifically, "Invalid value YOUR_PROJECT_ID". For more information see setting your Project ID.
private static final String projectId = "YOUR_PROJECT_ID"`
  1. Code Checkout Instructions
  2. Pre-requisites: install Java 6, Git, and Maven. You may need to set your JAVA_HOME environment variable as well.
  3. Download code:
cd some_directory
git clone https://github.com/GoogleCloudPlatform/compute-getting-started-java.git
cd compute-getting-started-java
cp ~/Downloads/client_secret_[id-unique-to-your-project-application].json src/main/resources/client_secrets.json
nano src/main/java/com/google/api/services/samples/computeengine/cmdline/ComputeEngineSample.java
  1. In your editor update the YOUR_PROJECT_ID value as specified above. Save and exit the editor.
  2. Compile code using Maven using the following command:
mvn compile
  1. Execute code using Maven via the following command:
mvn -q exec:java
  1. Import the code into Eclipse and running it from there
  2. Prerequisites: install Eclipse and the Maven plugin for Eclipse.
  3. Download code as specified above.
  4. File -> Import -> Maven -> Existing Maven Projects -> Next.
  5. Select your project directory as your "Root Directory," and click "Finish."
  6. Right-click on project compute-engine-cmdline-sample
  7. Run As > Java Application
  8. If asked, type "ComputeEngineSample" and click OK
  9. Application output will display in the Console.

compute-getting-started-java's People

Contributors

paulrashidi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.