arcgis-maps-sdk-java-samples icon indicating copy to clipboard operation
arcgis-maps-sdk-java-samples copied to clipboard

ArcGIS Maps SDK for Java samples

ArcGIS Runtime API for Java Samples

Link: ArcGIS Developers home Link: Documentation Link: API Reference Link: Tutorials Link: Demos Link: Toolkit

Link: Esri Community ArcGIS Developers Twitter Link: ArcGIS Runtime SDKs Blog Link: ArcGIS Blog for Developers

Gradle build

Welcome to the home of the ArcGIS Runtime API for Java samples! The ArcGIS Runtime API for Java is used to build mapping, location, and GIS applications for desktop applications running on Windows, Mac, or Linux. This repo contains a set of sample projects demonstrating how to accomplish various mapping and geospatial tasks with the ArcGIS Runtime API for Java.

Choose Camera Controller sample preview

Browse the category directories to explore the samples. Each sample is an individual Gradle project that can be run standalone. The Gradle buildscripts have tasks for running the application, building a jar, and distributing the app as a zip.

Installing Gradle is not necessary since each sample includes the Gradle wrapper.

Accessing Esri location services, including basemaps, routing, and geocoding, requires authentication using either an ArcGIS identity or an API Key:

  1. ArcGIS identity: An ArcGIS named user account that is a member of an organization in ArcGIS Online or ArcGIS Enterprise.
  2. API key: A permanent key that gives your application access to Esri location services. Visit your ArcGIS Developers Dashboard to create a new API key or access an existing API key.

Note: in the following instructions for setting the API key, if a gradle.properties file does not already exist in the /.gradle folder within your home directory, a Gradle task in the samples build.gradle file will generate one for you.

Instructions

IntelliJ IDEA

  1. Open IntelliJ IDEA and select File > Open....
  2. Choose one of the sample project directories (not the category folder) and click OK.
  3. Select File > Project Structure... and ensure that the Project SDK and language level are set to use Java 11 or Java 17.
  4. Store your API key in the gradle.properties file located in the /.gradle folder within your home directory. The API key will be set as a Java system property when the sample is run.
    apiKey = yourApiKey
    
  5. Open the Gradle view with View > Tool Windows > Gradle.
  6. In the Gradle view, double-click the run task under Tasks > application to run the app.

Note: if you encounter the error Could not get unknown property 'apiKey' for task ':run' of type org.gradle.api.tasks.JavaExec. you may have to set the Gradle user home in the IntelliJ Gradle settings to the /.gradle folder in your home directory.

Eclipse

  1. Open Eclipse and select File > Import.
  2. In the import wizard, choose Gradle > Existing Gradle Project, then click Next.
  3. Choose one of the sample project directories (not the category folder) as the project root directory.
  4. Click Finish to complete the import.
  5. Store your API key in the gradle.properties file located in the /.gradle folder within your home directory. The API key will be set as a Java system property when the sample is run.
    apiKey = yourApiKey
    
  6. Open the Gradle Tasks view with Window > Show View > Other... > Gradle > Gradle Tasks.
  7. In the Gradle Tasks view, double-click the run task under {project_name} > application to run the app.

Terminal

  1. cd into one of the sample project directories (not the category folder).
  2. Run gradle wrapper to create the Gradle Wrapper
  3. Store your API key in the gradle.properties file located in the /.gradle folder within your home directory. The API key will be set as a Java system property when the sample is run.
  4. Run ./gradlew run on Linux/Mac or gradlew.bat run on Windows to run the app.

Java 11

Java 11 users may find exceptions when running the project if their library path is still set for Oracle JDK 1.8 (see the OpenJavaFX docs for more information). A workaround for this is to add the following argument in the run task of the Gradle buildscript:

systemProperty "java.library.path", "C:\tmp"

Offline sample data

Some samples require offline data. A samples-data directory will automatically download to the project root when the Gradle project is configured/imported.

Requirements

See the ArcGIS Runtime API's system requirements.

Issues

Find a bug or want to request a new feature? Please let us know by submitting an issue.

Contributing

Esri welcomes contributions from anyone and everyone. Please see our guidelines for contributing.

New to Git? Check out our Working with Git guide.

Licensing

Copyright 2022 Esri

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's license.txt file.