AoInitialize and binding

3326
7
02-16-2011 03:06 PM
KenSimoncic
New Contributor
With ArcGIS 10, I decided to convert some code from using the C++ API to using the Java API.  With Arc installed on my personal machine with a node locked liscense (and no previous version installed) I was able call the EngineInitializer.Initialize method and then the AoInitialize method and it worked fine.  I then tried to run this same code on a machine that has floating licenses and may have had previous versions of Arc installed and I get an exception thrown from the AoInitialize call.  I don't have the error in front of me but it indicated that I need to bind to a specific version before calling AoInitialize.  I've seen VB.Net and C++ versions of this posted but nothing for java, not even in the sample code that I found here:
http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/index.html#/A_visual_Hello_Worl...
Does anyone know of an example of this or had any success doing this?
Thanks
0 Kudos
7 Replies
ReneRubalcava
Frequent Contributor
Not sure if this will help, but I had found this somewhere to check out licenses and it has worked for me so far.
This will initialize the lowest available license
package org.lacsd.services.helpers;

import java.io.IOException;
import java.net.UnknownHostException;

import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.system.esriLicenseStatus;

public class LicenseHelper {
 /**
  * Initializes the lowest available ArcGIS License
  */
 public static AoInitialize initializeArcGISLicenses()
 {
  EngineInitializer.initializeEngine();
  AoInitialize aoInit = null;
  try {
   aoInit = new AoInitialize();
  } catch (UnknownHostException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  try
  {
   System.out.println("license type: " + esriLicenseStatus.esriLicenseAvailable);
   if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable)
   {
    aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
   }
   else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcServer) == esriLicenseStatus.esriLicenseAvailable)
   {
    aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer);
   }
   else if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeArcInfo) == esriLicenseStatus.esriLicenseAvailable)
   {
    aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo);
   }
   else
   {
    System.err.println("Could not initialize an Engine or ArcView license. Exiting application.");
    System.exit(-1);
   }
   
   // do any extra checkouts here, could probably expand to make sure extension available
   // aoInit.checkOutExtension(com.esri.arcgis.system.esriLicenseExtensionCode.esriLicenseExtensionCodeNetwork);
  }
  catch (Exception e)
  {
   e.printStackTrace();
  }
  
  return aoInit;
 }
}
0 Kudos
KenSimoncic
New Contributor
Your code is very similar to what I am doing.  The problem is that when I call AoInitialize(), I catch an AutomationException that says "ArcGIS product not specified.  You must first bind to an ArcGIS version prior to using any ArcGIS components."  I added code:
           VersionManager vm = new VersionManager();
           vm.loadVersion(com.esri.arcgis.version.esriProductCode.esriArcGISDesktop,
                           "10.0");
 

But now I'm getting an UnsatisfiedLinkError : com.esri.arcgis.interop.NativeAuth.getNegociateMessage()[B
In the Java console it indicates that it is looking for a ntvauth dll which doesn't exist.  I'm wondering if I'm going down a path that was not intended due to an incomplete backout of the 9.3 version that was on this machine before.
0 Kudos
KenSimoncic
New Contributor
It seems that the code in AoInitialize has some dependencies that don't like when you are pointing to an arcobjects.jar file that is not in the standard location.  I had bundled the jar file in a war file that was deployed to a particular location but that caused me to have all sorts of problems.  I removed the arcobjects.jar file from my war file and added the bootstrapping code that I eventually stumbled across on this site and have been able to successfully initialize my license.  Now on to my next issue...
0 Kudos
RodelVelasco
New Contributor
Hi,

Can you share the workaround to this problem please.

Thanks


It seems that the code in AoInitialize has some dependencies that don't like when you are pointing to an arcobjects.jar file that is not in the standard location.  I had bundled the jar file in a war file that was deployed to a particular location but that caused me to have all sorts of problems.  I removed the arcobjects.jar file from my war file and added the bootstrapping code that I eventually stumbled across on this site and have been able to successfully initialize my license.  Now on to my next issue...
0 Kudos
TomSchuller
Occasional Contributor III
Hy,
could you try to use the JRE included in your ArcGIS installation?

Tom
0 Kudos
AdityaTadakaluru
New Contributor
0 Kudos
KenSimoncic
New Contributor
Added code before call to AOInitialize that went something like:

File jarFile = new File(<put the full path to arcobjects.jar here>);

URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
Class <URLClassLoader> sysclass = URLClassLoader.class;

try{
    Method method = sysclass.getDeclaredMethod("addURL", new Class[]{ URL.class} );
    method.setAccessible(true);
    method.invoke(sysloader, new Object[]{ jarFile.toURI().toURL() } );
}
catch{
// handle error in here
}
0 Kudos