comparison src/java/de/intevation/mxd/ArcGISInitializer.java @ 111:104af51a4717

Load the arcobjects.jar from ArcGIS install folder.
author vc11884admin@VC11884.win.bsh.de
date Tue, 14 Jun 2011 12:33:28 +0200
parents 163d474165b0
children f4eb506499f5
comparison
equal deleted inserted replaced
103:163d474165b0 111:104af51a4717
1 package de.intevation.mxd; 1 package de.intevation.mxd;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.io.File; 4 import java.io.File;
5 import java.lang.reflect.Method;
6 import java.net.URL;
7 import java.net.URLClassLoader;
5 8
6 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
7 10
8 import com.esri.arcgis.system.AoInitialize; 11 import com.esri.arcgis.system.AoInitialize;
9 import com.esri.arcgis.system.EngineInitializer; 12 import com.esri.arcgis.system.EngineInitializer;
33 * Init ArcGIS Java Objects. 36 * Init ArcGIS Java Objects.
34 */ 37 */
35 public boolean initArcGIS () 38 public boolean initArcGIS ()
36 throws IOException { 39 throws IOException {
37 logger.debug("initArcGIS()"); 40 logger.debug("initArcGIS()");
38 EngineInitializer.initializeEngine(); 41
39 aoInit = new AoInitialize(); 42 String engineInstallDir = System.getenv("AGSENGINEJAVA");
40 engineInstallDir = System.getenv("AGSENGINEJAVA"); 43 if(engineInstallDir == null) {
41 File installDir = new File(engineInstallDir);
42 if(!installDir.exists()) {
43 engineInstallDir = System.getenv("AGSDESKTOPJAVA"); 44 engineInstallDir = System.getenv("AGSDESKTOPJAVA");
44 installDir = new File(engineInstallDir); 45 if(engineInstallDir == null) {
45 if(!installDir.exists()) {
46 logger.error("Could not find ArcGIS Environment. \n" + 46 logger.error("Could not find ArcGIS Environment. \n" +
47 "AGSENGINEJAVA or AGSDESKTOPJAVA not set."); 47 "AGSENGINEJAVA or AGSDESKTOPJAVA not set.");
48 return false; 48 return false;
49 } 49 }
50 }
51
52 //Obtain the relative path to the arcobjects.jar file
53 String jarPath = engineInstallDir + "java" + File.separator + "lib" +
54 File.separator + "arcobjects.jar";
55
56 //Create a new file
57 File jarFile = new File(jarPath);
58
59 //Test for file existence
60 if(!jarFile.exists()){
61 logger.error("The arcobjects.jar was not found in the following location: " +
62 jarFile.getParent());
63 logger.error("Verify that arcobjects.jar can be located in the specified folder.");
64 logger.error("If not present, try uninstalling your ArcGIS software and reinstalling it.");
65 System.exit(0);
50 } 66 }
51 else { 67
52 return true; 68 //Helps load classes and resources from a search path of URLs
69 URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
70 Class<URLClassLoader> sysclass = URLClassLoader.class;
71
72 try {
73 Method method = sysclass.getDeclaredMethod("addURL", new Class[]{URL.class});
74 method.setAccessible(true);
75 method.invoke(sysloader, new Object[]{jarFile.toURI().toURL()});
53 } 76 }
77 catch (Throwable throwable) {
78 throwable.printStackTrace();
79 logger.error("Could not add arcobjects.jar to system classloader");
80 System.exit(0);
81 }
82
83 EngineInitializer.initializeEngine();
84
85 aoInit = new AoInitialize();
54 return true; 86 return true;
55 } 87 }
56 88
57 /** 89 /**
58 * Init ArcGIS License. 90 * Init ArcGIS License.
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)