ArcGIS Runtime SDK for Java

Develop your first map app with Maven

Use the steps below to create a basic mapping app using the Maven build tool. The steps use the Eclipse IDE, but other IDEs have Maven support too.

Make sure your development machine meets the System requirements 100.3.

Create a Maven project in Eclipse

  1. In Eclipse, click File > New > Project in the menu bar. In the New Project dialog, select the Maven folder and click Maven Project. Click Next.

    New Project wizard dialog with Maven Project selected
  2. In the next dialog, check the box that says Create a simple project (skip archetype selection). Click Next.
  3. In the last dialog, under Artifact, enter com.mycompany.app for the Group Id and app for the Artifact Id. Leave the rest with the defaults. Click Finish.

    In the Package Explorer, your project should look as follows:

    Package Explorer with default maven project structure

Add SDK dependencies to your pom

  1. In the Package Explorer, double-click the pom.xml file. In the editor, select the pom.xml tab. It should look similar to the following:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mycompany.app</groupId>
      <artifactId>app</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </project>

  2. Update the pom to add the SDK dependencies.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mycompany.app</groupId>
      <artifactId>app</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    
      <repositories>
        <repository>
          <id>arcgis</id>
          <url>https://esri.bintray.com/arcgis</url>
        </repository>
      </repositories>
    
      <pluginRepositories>
        <pluginRepository>
          <id>arcgis-plugin</id>
          <url>https://esri.bintray.com/arcgis</url>
        </pluginRepository>
      </pluginRepositories>
    
      <dependencies>
        <dependency>
          <groupId>com.esri.arcgisruntime</groupId>
          <artifactId>arcgis-java</artifactId>
          <version>100.3.0</version>
        </dependency>
      </dependencies>
    
      <build>
          <plugins>
            <!--ArcGIS Java Maven Plugin-->
            <plugin>
              <groupId>com.esri.arcgisruntime</groupId>
              <artifactId>arcgis-java-maven-plugin</artifactId>
              <version>1.0</version>
              <configuration>
                <version>100.3.0</version>
              </configuration>
            </plugin>
          </plugins>
      </build>
    </project>

  3. Save the file. Then, right-click the pom.xml file in the Package Explorer and select Run As > Maven build....
  4. In the Edit Configuration dialog, create a new configuration with name arcgis. In the Goals field, enter arcgis-java:arcgis. Click Run to run the goal.

    The ArcGIS Java SDK Plug-in for Maven will download the SDK's native libraries to the user's home directory.

    Note:

    It may take a minute to download the native libraries depending on your network speed, but this will only happen the first time you use the SDK.

Develop a JavaFX map app

  1. Under the project's src/main/java source directory, create the package structure com.mycompany.app. In the app package, create a new class called MyMapApp.

    Package Explorer showing class MyMapApp in package com.mycompany.app
  2. Double-click the class file in the Package Explorer and replace the code with the following JavaFX application:

    package demoApp;
     import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
     public class MyMapApp extends Application {
       @Override
      public void start(Stage stage) throws Exception {
         // create stack pane and application scene
        StackPane stackPane = new StackPane();
        Scene scene = new Scene(stackPane);
         // set title, size, and add scene to stage
        stage.setTitle("Display Map Sample");
        stage.setWidth(800);
        stage.setHeight(700);
        stage.setScene(scene);
        stage.show();
      }
       /**
       * Opens and runs application.
       *
       * @param args arguments passed to this application
       */
      public static void main(String[] args) {
         Application.launch(args);
      }
    }

  3. Right-click the code in the editor and choose Run As > Java Application. The app will open to show an imagery basemap with window titled "Display Map Sample".
  4. Following imports are for adding a basemap to a map and displaying that map to the map view.

    import com.esri.arcgisruntime.mapping.ArcGISMap;
    import com.esri.arcgisruntime.mapping.Basemap;
    import com.esri.arcgisruntime.mapping.view.MapView;

  5. After the class definition, a private variable for map view is added so it can be dispose of when application is finished.

    public class MyMapApp extends Application {
    
    
      private MapView mapView;

  6. In the start function, after the stage.show() line the following tasks:
    1. Creates an ArcGISMap class, which defines the content of the map.
    2. Adds a basemap to the ArcGISMap class showing Imagery mapping.
    3. Creates a MapView JavaFX visual component that's linked to the Map class.
    4. Adds MapView to JavaFX application using the StackPane layout.

    // create a ArcGISMap with the a Basemap instance with an Imagery base layer
    ArcGISMap map = new ArcGISMap(Basemap.createImagery());
    
    
    // set the map to be displayed in this view
    mapView = new MapView();
    mapView.setMap(map);
    
    
    // add the map view to stack pane
    stackPane.getChildren().addAll(mapView);

  7. Overrides the stop method to dispose of application resources when the app closes.

    /**
     * Stops and releases all resources used in application.
     */
    @Override
    public void stop() {
      if (mapView != null) {
        mapView.dispose();
      }
    }

  8. Example of what the map should look like. You can use the mouse to zoom and pan the map.