This tutorial shows how to prepare your local machine for Java development, including developing Java apps that run on Google Cloud. Follow this tutorial to install Java and relevant tools.
Objectives
- Install a JDK (Java Development Kit).
- Install a build automation tool.
- (Optional) Install an IDE or editor.
- (Optional) Install IDE Cloud SDK plugin.
- (Optional) Install the Functions Framework plugin.
- Install the Cloud SDK.
- Install the Google Cloud Client Library for Java.
Install a JDK (Java Development Kit)
Install an OpenJDK 11 or OpenJDK 8 distribution. The following is a list of some of the distributions you can use:
- SdkMan A tool for managing multiple SDK's including many OpenJDK's, Maven and Gradle.
- AdoptOpenJDK OpenJDK builds built by RedHat.
- Zulu Community builds Zulu Community builds of the OpenJDK.
- jdk.java.net Java Development Kit builds, from Oracle.
Ensure that the following environment variables are set:
- JAVA_HOME: Points to the base of the JDK installation.
- PATH: Includes
$JAVA_HOME/bin
.
Install a build automation tool
Apache Maven, Gradle, and SBT are package management options that can help build Java app dependencies quickly and consistently across platforms.
Install the Cloud SDK
The
Cloud SDK
is a set of tools for Google Cloud. It contains gcloud
, gsutil
, and
bq
, which you can use to access Compute Engine, Cloud Storage,
BigQuery, and other products and services from the command line. You can
run these tools interactively or in your automated scripts.
(Optional) Install an IDE or editor
Popular editors (in no particular order) used to develop Java apps include, but are not limited to:
- Eclipse by Eclipse Foundation
- IntelliJ IDEA and/or Webstorm by JetBrains
- Atom by GitHub
These editors (sometimes with the help of plugins) give you everything from syntax highlighting, intelli-sense, and code completion to fully integrated debugging capabilities.
(Optional) Install IDE Cloud SDK plugin
For access to helpful functions within your editor, check out the Google-sponsored plugins for Eclipse or IntelliJ.
(Optional) Install the Functions Framework plugin
The Functions Framework plugin allows you to run and test Java functions on your local machine.
If you're using Apache Maven, add the following to your pom.xml
file:
<dependency>
<groupId>com.google.cloud.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>1.0.1</version>
<scope>provided</scope>
</dependency>
If you're using Gradle, add the following to your build.gradle
file:
dependencies {
implementation 'com.google.cloud.functions:functions-framework-api:1.0.1'
}
Use the Google Cloud Client Library for Java
Use the Google Cloud Client Library for Java to integrate with Google Cloud services, such as Datastore and Cloud Storage. You can install the package for an individual API, such as BigQuery, as shown in the following example.
Installing the client library
If you are using Maven, add
the following to your pom.xml
file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using IntelliJ or Eclipse, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
Set up authentication
To run the client library, you must first set up authentication.
Using the client library
What's next
(Optional) Use the Maven or Gradle plugin for App Engine
If you are developing in the App Engine standard or flexible environment, you can use plugins for both Apache Maven and Gradle build tools that provide convenient functions for developing, testing, and deploying your apps directly.
For App Engine standard environments
Use the Maven App Engine plugin or Gradle plugin for App Engine standard environments.
For App Engine flexible environments
Use the Maven App Engine plugin or Gradle plugin for App Engine flexible environments.
More resources
- Browse the documentation for Google Cloud products.
- Clone the Java samples repository from GitHub.
- Explore Java tutorials submitted by the community.