Setting Up a Java Development Environment Stay organized with collections Save and categorize content based on your preferences.
This tutorial shows how to prepare your local machine forJava development, including developing Java apps that run onGoogle Cloud. Follow these steps to installJava and relevant tools.
Tip: If you want to get started quickly,Cloud Shell Editor provides IDE supportfor the full development cycle of Google Kubernetes Engine and Cloud Runapplications. Cloud Shell Editor is based onCode - OSSand comes with the Google Cloud CLI and Cloud Code toolspreinstalled.Objectives
- Install a JDK (Java Development Kit).
- Install a build automation tool.
- Install the gcloud CLI.
- (Optional) Install an IDE or editor.
- (Optional) Install IDE Google Cloud plugin.
- Install the Cloud Client Libraries for Java.
- Set up authentication.
Install a JDK (Java Development Kit)
You may choose any Java distribution of your choice by ensuring thatthe following environment variables are set:
- JAVA_HOME: Points to the base of the JDK installation.
- PATH: Includes
$JAVA_HOME/bin
.
Eclipse Temurin is the recommended OpenJDK (Java Development Kit) distribution for use withGoogle Cloud. Temurin is open-source licensed, Java SE TCK-certified, and testedto ensure production-quality performance and security.
(Recommended) Installing Temurin
Temurin's installation instructions vary by operating system.
- Binaries are available fordownload.
- For Docker containers, use theofficial 'eclipse-temurin' image.
If you are using Compute Engine boot images, you can use the following installation scripts.
CentOS/RHEL/Rocky
- Determine the major version of CentOS/RHEL/Rocky Linux:
eval "$(grep VERSION_ID /etc/os-release)"eval "$(grep ^ID= /etc/os-release)"OLD_IFS=$IFSIFS='.'read -ra split_version<<< "$VERSION_ID"IFS=$OLD_IFSMAJOR_VERSION=$split_version
- Create the Adoptium source repo file, `/etc/yum.repos.d/adoptium.repo`:
sudo tee /etc/yum.repos.d/adoptium.repo<< EOM[Adoptium]name=Adoptiumbaseurl=https://packages.adoptium.net/artifactory/rpm/$ID/$MAJOR_VERSION/\$basearchenabled=1gpgcheck=1gpgkey=https://packages.adoptium.net/artifactory/api/gpg/key/publicEOM
- Update package lists:
sudo yum update -y
- Install Temurin:
sudo yum install -ytemurin-17-jdk
- Verify installation:
java -version
Debian/Ubuntu
- Install the public repo GPG key. If you are using Ubuntu 16.4, pass the key through
gpg --dearmor
before saving to file. (ex:sudo wget ... | gpg --dearmor | sudo tee ...
)sudo mkdir -p /etc/apt/keyringssudo wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /etc/apt/keyrings/adoptium.asc
- Determine the name of the Linux distribution, and create the source list file,
/etc/apt/sources.list.d/adoptium.list
:eval "$(grep VERSION_CODENAME /etc/os-release)"sudo tee /etc/apt/sources.list.d/adoptium.list<< EOMdeb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $VERSION_CODENAME mainEOM
- Update package lists:
sudo apt update -y
- Install Temurin:
sudo apt install -ytemurin-17-jdk
- Verify installation:
java -version
SLES
- Determine the major version of SLES:
eval "$(grep VERSION_ID /etc/os-release)"OLD_IFS=$IFSIFS='.'read -ra split_version<<< "$VERSION_ID"IFS=$OLD_IFSMAJOR_VERSION=$split_version
- Install the public repository GPG key:
sudo mkdir -p /etc/zypp/keyringssudo wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /etc/zypp/keyrings/adoptium.ascsudo rpm --import /etc/zypp/keyrings/adoptium.asc
- Determine the version of SLES, and register the Adoptium repository:
sudo zypper ar -f "https://packages.adoptium.net/artifactory/rpm/sles/$MAJOR_VERSION/$(uname -m)" adoptium
- Update package lists:
sudo zypper update -y
- Install Temurin:
sudo zypper install -ytemurin-17-jdk
- Verify installation:
java -version
Windows
To install Temurin, run PowerShell version 3.0 or higher as an administrator with the following commands.
- Download Temurin. The
Invoke-WebRequest
command in the instructions below requires PowerShell 3.0 or newer.$JdkVersion =17$JdkUrl = "https://api.adoptium.net/v3/binary/latest/$JdkVersion/ga/windows/x64/jdk/hotspot/normal/eclipse?project=jdk"$JdkExtractionPath = "C:\temurin-$JdkVersion-jdk"$JdkDownload = "$JdkExtractionPath.zip"[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls12'Invoke-WebRequest -Uri $JdkUrl -OutFile $JdkDownloadExpand-Archive $JdkDownload -DestinationPath $JdkExtractionPath -Force
- Set the
JAVA_HOME
andPath
variables:pushd $JdkExtractionPath$JdkPath = (Get-ChildItem).FullNamepopd[System.Environment]::SetEnvironmentVariable('JAVA_HOME', $JdkPath, 'Machine')
- (Optional) Refresh your session's `$env:Path` value. Otherwise, start a new session:
$MachinePath = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')$UserPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')$env:Path = "$MachinePath;$UserPath"
- Verify installation:
java -version
Install a build automation tool
Apache Maven,Gradle,andSBT are package management options that can help build Java app dependenciesquickly and consistently across platforms.
Install the gcloud CLI
Thegcloud CLI is a set of tools for Google Cloud. It containsgcloud
andbq
, which you can use to access Compute Engine, Cloud Storage,BigQuery, and other products and services from the command line. You canrun these tools interactively or in your automated scripts.
(Optional) Install an IDE or editor
Popular editors (in no particular order) used to develop Javaapps include, but are not limited to:
- Visual Studio Code
- IntelliJ IDEA and/or Webstorm by JetBrains
- Eclipse by Eclipse Foundation
- Atom by GitHub
These editors (sometimes with the help of plugins) give you everything fromsyntax highlighting, intelli-sense, and code completion to fully integrateddebugging capabilities.
(Optional) Install an IDE plugin
For access to helpful functions within your editor, check out the followingplugins:
Install the Cloud Client Libraries for Java
Use theCloud Client Libraries for Java to integrate with Google Cloudservices, such as Datastore and Cloud Storage. You can install thepackage for an individual API, such as BigQuery, as shown in thefollowing example.
If you are usingMaven, addthe following to yourpom.xml
file. For more information aboutBOMs, seeThe Google Cloud Platform Libraries BOM.
<!-- Using libraries-bom to manage versions.See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM --><dependencyManagement> <dependencies> <dependency> <groupId>com.google.cloud</groupId> <artifactId>libraries-bom</artifactId> <version>26.62.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement><dependencies> <dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-bigquery</artifactId> </dependency></dependencies>
If you are usingGradle,add the following to your dependencies:
implementation platform('com.google.cloud:libraries-bom:26.45.0')implementation 'com.google.cloud:google-cloud-bigquery'
If you are usingsbt, addthe following to your dependencies:
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.42.2"
If you're using Visual Studio Code, 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.
Note: Cloud Java client libraries do not currently support Android.Set up authentication
To run the client library, you must first set up authentication.
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, seeAuthenticate for using client libraries.
Use the client library
// Imports the Google Cloud client libraryimportcom.google.cloud.bigquery.BigQuery;importcom.google.cloud.bigquery.BigQueryOptions;importcom.google.cloud.bigquery.Dataset;importcom.google.cloud.bigquery.DatasetInfo;publicclassQuickstartSample{publicstaticvoidmain(String...args)throwsException{// Instantiate a client. If you don't specify credentials when constructing a client, the// client library will look for credentials in the environment, such as the// GOOGLE_APPLICATION_CREDENTIALS environment variable.BigQuerybigquery=BigQueryOptions.getDefaultInstance().getService();// The name for the new datasetStringdatasetName="my_new_dataset";// Prepares a new datasetDatasetdataset=null;DatasetInfodatasetInfo=DatasetInfo.newBuilder(datasetName).build();// Creates the datasetdataset=bigquery.create(datasetInfo);System.out.printf("Dataset %s created.%n",dataset.getDatasetId().getDataset());}}
Configure endpoints for the client library
If you use APIs that support regional endpoints, use endpoints to configure which server to send requests to. For example, with theGoogle.Cloud.Dataproc.V1 API, you might configure a client endpoint. You can read more about regional endpoints for Dataprochere. Be sure to replaceMY-PROJECT with your project name andus-central1 with the region appropriate for your configuration in the following example:
ClusterControllerSettingssettings=ClusterControllerSettings.newBuilder().setEndpoint("us-central1-dataproc.googleapis.com:443").build();try(ClusterControllerClientclusterControllerClient=ClusterControllerClient.create(settings)){StringprojectId="MY-PROJECT";Stringregion="us-central1";Clustercluster=Cluster.newBuilder().build();}
What's next
(Optional) Use the Maven or Gradle plugin for App Engine
If you are developing in the App Engine standard or flexibleenvironment, you can use plugins for both Apache Maven and Gradle build toolsthat provide convenient functions for developing, testing, and deploying yourapps directly.
For App Engine standard environments
Use theMaven App Engine plugin orGradle plugin for App Engine standard environments.
For App Engine flexible environments
Use theMaven App Engine plugin orGradle plugin for App Engine flexible environments.
More resources
- Browse thedocumentation for Google Cloud products.
- Clone theJava samples repository from GitHub.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-18 UTC.