
// Get the ArcGIS Engine runtime, if it is available
String arcObjectsHome = "E:\\Program Files\\ArcGIS\\Desktop10.0\\"
// If no runtime is available, exit application gracefully
if (arcObjectsHome == null) {
System.err
.println("You must have the ArcGIS Engine Runtime installed in order to execute this application.")
System.err
.println("Install the product above, then re-run this application.")
System.err.println("Exiting execution of this application...")
System.exit(-1)
}
// Obtain the relative path to the arcobjects.jar file
String jarPath = arcObjectsHome + "java" + File.separator + "lib"
+ File.separator + "arcobjects.jar"
// Create a new file
File jarFile = new File(jarPath)
// Test for file existence
if (!jarFile.exists()) {
System.err
.println("The arcobjects.jar was not found in the following location: "
+ jarFile.getParent())
System.err
.println("Verify that arcobjects.jar can be located in the specified folder.")
System.err
.println("If not present, try uninstalling your ArcGIS software and reinstalling it.")
System.err.println("Exiting execution of this application...")
System.exit(-1)
}
// Helps load classes and resources from a search path of URLs
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 (Throwable throwable) {
throwable.printStackTrace()
System.err
.println("Could not add arcobjects.jar to system classloader")
System.err.println("Exiting execution of this application...")
System.exit(-1)
}
}
1. 首先是二次开发环境的安装(AE 10.1),需要装下面两项:2. AE 10.1貌似只支持VS2010,VS2010以下的VS版本不支持,VS2012也不支持,安装了不支持的VS版本会出现以下提示:
3. 安装后在开发时可以添加引用来使用AE提供的接口,如下图:
4.在程序初始化之前需要检查AE组件的授权状态,代码如下:
[csharp] view plain copy
private void InitializeComponent()
{
IAoInitialize m_AoInitialize = new AoInitializeClass()
esriLicenseStatus esriLicenseStatuslicenseStatus = esriLicenseStatus.esriLicenseUnavailable
esriLicenseStatus licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo)
if (licenseStatus != esriLicenseStatus.esriLicenseAvailable)
{
System.Diagnostics.Trace.WriteLine("Invalid Licensing.")
return
}
......
假如组件完全没有授权,在调试时会出现下面错误提示:
假如有部分组件授权过期了,会提示你哪些组件过期了:
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)