ArcGIS Runtime SDK for Java

Local Server

Local Server, an optional component of ArcGIS Runtime SDK for Java, is primarily for executing offline geoprocessing tasks in your ArcGIS Runtime apps. These tasks work in the same way as geoprocessing tasks published from ArcGIS Online or ArcGIS Enterprise. Running a geoprocessing task on Local Server requires an ArcMap or ArcGIS Pro geoprocessing package (.gpk or .gpkx file). These packages are authored in ArcGIS Desktop either using Model Builder or by writing a Python script. See Author and publish a geoprocessing model for details on publishing geoprocessing packages.

Local Server also allows developers to consume map image layers or feature layers from content in an ArcMap or ArcGIS Pro map package (.mpk or .mpkx file). These packages are authored and created using ArcGIS Desktop. This capability has been included to support workflows in earlier versions of ArcGIS Runtime. If you're starting a new project and require offline data, use sync-enabled geodatabases, which are generated from feature services. See Create an offline map for details.

Local Server can be downloaded for Windows (32- and 64-bit) and Linux platforms (64-bit). Local Server is not supported on macOS.

To develop with Local Server, you must set up your development environment's access to it. To deploy your app with Local Server capabilities, you must set up your app's access to the Local Server.

Before you use Local Server capabilities, you must start the Local Server instance.

Installing the Local Server SDK

Install Local Server on Windows

  1. Ensure your development machine meets the system requirements for ArcGIS Runtime Local Server SDK Java. Development and deployment machines must also have the following packages installed:
    • Microsoft Visual C++ 2015 Update 3 Redistributable Package (x86 or x64 to match your application architecture).
    • Development and deployment on Windows 8.1, Windows Server 2012, Windows Server 2012 R2, or Windows 7 SP1 also requires installation of the Windows 10 Universal C Runtime via the following Windows Updates or Update Packages:
      • Update for Windows 8.1 (KB2999226)
      • Update for Windows 8.1 for x64-based Systems (KB2999226)
      • Update for Windows Server 2012 R2 (KB2999226)
      • Update for Windows Server 2012 (KB2999226)
      • Update for Windows 7 (KB2999226)
      • Update for Windows 7 for x64-based Systems (KB2999226)
  2. Download Local Server from the Downloads page. You'll need to log in with an ArcGIS developer account. Sign up for a free account if you haven't already. Save the file to a location on your development machine.
  3. Extract the file you downloaded, and then double-click the Setup.exe file to start the installation wizard.
  4. Follow the instructions. In the Destination Folder dialog, you can change the default installation directory by clicking the Change button, then navigating to the desired folder. Make sure you have write permissions to this folder on your development machine. Ensure no other users are using the folder.
  5. On the last panel of the wizard, click Finish. The ArcGIS Runtime Local Server is now installed at the installation folder you chose in the previous step.

Install Local Server on Linux

  1. Make sure your development machine meets the system requirements for ArcGIS Runtime Local Server SDK Java.
  2. Download Local Server from the Downloads page. You'll need to log in with an ArcGIS developer account. Sign up for a free account if you haven't already. Save the file to a location on your development machine.
  3. Unzip the ArcGIS Runtime gzip file to get the tar file. At the prompt, type gunzip .tar.gz.
  4. Extract the product .tar file to create the installation directory: tar xvf .tar.
  5. Follow the on-screen instructions. In the Choose Install Folder dialog, you can change the default installation directory by clicking the Choose button, and then navigating to the desired directory. Make sure this directory is on your development machine and that you have write permissions to this directory. Ensure no other users are using the directory.
  6. On the last panel of the wizard, click Done. Local Server is now installed in the installation directory you chose in the previous step.
  7. If you are using an Enterprise Geodatabase connection which uses ODBC (SDE connection to netezza for example) you will need to modify init_user_params.sh to uncomment the following line:
    #
    # Enable this section to point to the native ODBC driver.  Note the path
    # may be different on your system. 
    #
    #export LIB_ODBC_DRIVER_MANAGER=/usr/lib64/libodbc.so.2
    The exact path may differ depending on your installation, and you may need to install the unixODBC-utf16-2.3.1-1.x86_64 or later library.
Note:

If you see Fontconfig error: Cannot load default config file on the console, Local Server cannot find fonts on your machine. Set the FONTCONFIG_PATH environment variable either in /etc/profile or explicitly—for example, export FONTCONFIG_PATH=/etc/fonts.

Installing database client software for enterprise geodatabase connections

If any of your Local Server packages make use of enterprise geodatabase connections (SDE), then you may need to install the client software for the database you are connecting to. The section on Database connections gives details on the configuration of database client software.

Set up your app's Local Server directory

As a developer, when you have installed the Local Server SDK, your applications that use Local Server will work because they'll use the installation directories referenced in the RUNTIMELOCALSERVER_100_0 Environment variable.

However when you deploy your application, you need to make the Local Server binaries available to your application in one of the following ways. The Local Server binaries for 32-bit platforms are in the 32 directory, and 64-bit binaries are in the 64 directory.

  • If you have not done so already, create a Local Sever deployment.
  • Copy the Local Server directory so that it is adjacent to your application executable file (so that the 32 or 64 folder is at the same level as your app's executable file).
  • Set your own custom location for the Local Server directory using the LocalServer.INSTANCE.setInstallPath("c:/myLocalServerInstall"); method and be sure to install the Local Server folder there as part of the app install.
  • You can set up your own RUNTIMELOCALSERVER_100_0 environment variable pointing to the Local Server directory; although this is typically used as a developer workflow.

Start a Local Server instance

You must start a Local Server instance if you want your app to use any services on the Local Server. Only one instance of the Local Server can be running at any time.

  1. Prior to requesting Local Server to start, it's good practice to check that your application can access the Local Server installation path.
    // check that local server install path can be accessed
    if (LocalServer.INSTANCE.checkInstallValid()) {
      server = LocalServer.INSTANCE;
      // ... place code to start local server
    
    
    } else {
      Platform.runLater(() -> {
        Alert dialog = new Alert(AlertType.INFORMATION);
        dialog.setHeaderText("Local Server Load Error");
        dialog.setContentText("Local Server install path couldn't be located.");
        dialog.showAndWait();
    
    
        Platform.exit();
      });
    }
  2. Once you have a valid Local Server directory, start the process.
    // start local server
    server.startAsync();
    // watch server status
    server.addStatusChangedListener(status -> {
      System.out.println("Server Status: " + status.getNewStatus().toString());
    });
  3. Once the Local Server has started, you can start services (such as geoprocessing services, for example) as described in the following sections.
  4. When an application is closed down, the Local Server should also be shut down by calling stopAsync.
    // stop local server
    if (LocalServer.INSTANCE.getStatus() == LocalServerStatus.STARTED) {
      LocalServer.INSTANCE.stopAsync();
    }
  5. The sample application in GitHub shows how to start and stop the Local Server.

Run geoprocessing services

Geoprocessing services can be used from Local Server with a geoprocessing package file (.gpk file). The geoprocessing packages are authored and published from ArcMap. For more information about geoprocessing, see Run a geoprocessing task.

A local geoprocessing service can be started provided that the Local Server is started. The following code shows how to start the service and set up a task to use the "Message in a bottle" sample geoprocessing package.

// start local geoprocessing service once local server has started
server.addStatusChangedListener(status -> {
  if (status.getNewStatus() == LocalServerStatus.STARTED) {
    try {
      String gpServiceURL = new File("./samples-data/local_server/Contour.gpk").getAbsolutePath();
      // need map server result to add contour lines to map
      localGPService =
        new LocalGeoprocessingService(gpServiceURL, ServiceType.ASYNCHRONOUS_SUBMIT_WITH_MAP_SERVER_RESULT);
    } catch (Exception e) {
      e.printStackTrace();
    }


    localGPService.addStatusChangedListener(s -> {
      // create geoprocessing task once local geoprocessing service is started
      if (s.getNewStatus() == LocalServerStatus.STARTED) {
        // add `/Contour` to use contour geoprocessing tool 
        GeoprocessingTask gpTask = new GeoprocessingTask(localGPService.getUrl() + "/Contour");
      }
    });
    localGPService.startAsync();
  }
});

Run map image layer services

Map services can be consumed from Local Server using a map package file. Provided that the Local Server is started, you can start a service. Once the service is started, the URL is obtained and used to add an ArcGISMapImageLayer to your map.

// start map image service
String mapServiceURL = new File("/path/to/file.mpk").getAbsolutePath();
LocalMapService mapImageService = new LocalMapService(mapServiceURL);
mapImageService.addStatusChangedListener(status -> {
  // check that the map service has started
  if (status.getNewStatus() == LocalServerStatus.STARTED) {
    // get the url of where map service is located
    String url = mapImageService.getUrl();
    // create a map image layer using url
    ArcGISMapImageLayer imageLayer = new ArcGISMapImageLayer(url);
    // set viewpoint once layer has loaded
    imageLayer.addDoneLoadingListener(() -> {
      if (imageLayer.getLoadStatus() == LoadStatus.LOADED && imageLayer.getFullExtent() != null) {
        mapView.setViewpoint(new Viewpoint(imageLayer.getFullExtent()));
      }
    });
    imageLayer.loadAsync();
    // add image layer to map
    mapView.getMap().getOperationalLayers().add(imageLayer);
  }
});
mapImageService.startAsync();
ArcGISMapImageLayer from a local map service

Run feature services

Feature services can also be consumed from a Local Server instance. As with map services, these services use a map package file (.mpk) that has been authored and published from ArcGIS Desktop.

The code below shows how to start the service, obtain the URL, and use this to add a feature layer to the map.

// start feature service
String featureServiceURL = new File("path/to/file.mpk").getAbsolutePath();
LocalFeatureService featureService = new LocalFeatureService(featureServiceURL);
featureService.addStatusChangedListener(status -> {
  if (status.getNewStatus() == LocalServerStatus.STARTED) {
    // get the url of where feature service is located
    String url = featureService.getUrl() + "/0";
    // create a feature layer using the url
    ServiceFeatureTable featureTable = new ServiceFeatureTable(url);
    featureTable.loadAsync();
    FeatureLayer featureLayer = new FeatureLayer(featureTable);
    featureLayer.addDoneLoadingListener(() -> {
      if (featureLayer.getLoadStatus() == LoadStatus.LOADED && featureLayer.getFullExtent() != null) {
        mapView.setViewpoint(new Viewpoint(featureLayer.getFullExtent()));
      }
    });
    featureLayer.loadAsync();
    // add feature layer to map
    map.getOperationalLayers().add(featureLayer);


  }
});
featureService.startAsync();