About accessing licensing and extensions for the geoprocessor
When a tool is executed in a program, a valid ArcGIS license is required. Tools from ArcGIS extensions, such as ArcGIS Spatial Analyst, require an additional license for that extension. If the necessary licenses are not available, a tool fails and returns the appropriate error messages.
A program must explicitly use AoIntialize and set the product to the appropriate level the tools requested or the program fails. An ArcGIS Engine license is equivalent to an ArcGIS Arcview license, while an ArcGIS Engine Enterprise Geodatabase license corresponds to an ArcGIS Editor license. ArcGIS Server is equivalent to an ArcInfo license.
AOInitialize is specific about the license it utilizes. If you request an ArcGIS Engine license, AOInitialize only looks for an ArcGIS Engine license and not an ArcView or any other license level. Therefore, depending on your installed software and licensing, ensure your application does the appropriate license checking and initialization. See the following code example:
The first call to AOInitialize that checks out a license determines the licensing for the lifetime of the application. Therefore, initialize the license requirements for all the necessary tools in your application. For example, if you use Clip and SpatialJoin in your application, check out an ArcInfo license since SpatialJoin requires ArcInfo licensing. You cannot check out an ArcView or ArcGIS Engine license for Clip, then check out an ArcInfo license for SpatialJoin.
public static void main(String[] args){
EngineInitializer.initializeEngine();
try{
com.esri.arcgis.system.AoInitialize ao = new
com.esri.arcgis.system.AoInitialize();
//Check out licenses.
if (ao.isProductCodeAvailable
(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcInfo) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
ao.initialize
(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcInfo);
else if (ao.isProductCodeAvailable
(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
ao.initialize
(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine);
else if (ao.isProductCodeAvailable
(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
ao.initialize
(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
ao.checkOutExtension
(com.esri.arcgis.system.esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);
//Do the geoprocessing work.
GeoProcessor gp = new GeoProcessor();
Slope slope = new Slope("C:/data/demlatgrd", "C:/data/output/slopeRaster");
gp.execute(slope, null);
//Clean up.
ao.checkInExtension
(esriLicenseExtensionCode.esriLicenseExtensionCodeSpatialAnalyst);
ao.shutdown();
}
catch (Exception e){
e.printStackTrace();
}
}