ArcGIS Runtime SDK for Java

Develop your first map app using the downloaded SDK

This topic describes how to create a basic mapping app using the Eclipse integrated development environment (IDE).

Develop an app with Eclipse

  1. Install ArcGIS Runtime SDK for Java and make sure your development machine meets the system requirements.
  2. In Eclipse, right-click in the Package Explorer and click New > Java Project.

    The New Java Project wizard appears.

  3. In the Project name text box, provide a project name, such as MyMapApp and click Next.
  4. Click the Libraries tab and click Add External JARs. Browse to the folder where you extracted the ArcGIS Java SDK and select all of the .jar files in the arcgis-runtime-sdk-java-100.4.0\libs directory. Click Finish.

    Your new project appears in the Project Explorer.

  5. Right-click the project and click New > Class. In the Java Class dialog box, give the package name of demoApp and enter the class name of MyMapApp.

    The settings in the dialog box should resemble those in the following image:

    Click Finish and your project in the Package Explorer should resemble the following image:

  6. To add the reference to the ArcGIS Java SDK API Reference (Javadoc) so that you can view a local version of it, expand the Referenced Libraries item, right-click arcgis-java-api.jar, and click Properties.
    Tip:

    The online version of this documentation is at API Reference.

  7. In the left pane of the dialog box, click Javadoc Location. Select the Javadoc in archive radio button. For the Archive path, browse to arcgis-runtime-sdk-java-100.4.0\libs folder and select the arcgis-java-api-javadoc.jar. Click Validate, and click OK.
  8. The arcgis-runtime-sdk-java-100.4.0 directory contains the resource and binary files needed for your ArcGIS Runtime application to execute. If you happen to be using the ARCGISRUNTIMESDKJAVA_100_4_0 system environment variable to point to this local directory, then the next step is optional for you.
  9. Using a file browser, drag and drop the unziped 'jniLibs' and 'resources' folders from the arcgis-runtime-sdk-java-100.4.0 directory into the top level of your project folder in Eclipse. When prompted, choose the option to copy files and folders. In Eclipse, your project should look like the following:

    Note:

    The jniLibs folder contains all of the native libs for all supported platforms. You only need to copy the ones specifically for the platform you're developing on. For example, if you're developing on a Mac, the only folder you will need to keep is the OSX64 folder.

    If you're developing on Windows, you will need the directx folder and either the WIN32 or WIN64 folder.

  10. You're now ready to start writing your app. Open your MyMapApp.java class file and replace the code with the following JavaFX application:

    package com.mycompany.app;
    
    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();
      }
      
      public static void main(String[] args) {
      
        Application.launch(args);
      }
    }

  11. Click Run.

    The app will open to show an imagery basemap with window titled "Display Map Sample".

  12. 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;

  13. 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;

  14. 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);

  15. 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();
      }
    }

  16. Click Run.

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