Mercurial > mxd2map
changeset 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 | 82a220ac7033 |
files | ChangeLog src/java/de/intevation/mxd/ArcGISInitializer.java |
diffstat | 2 files changed, 48 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Jun 10 14:04:03 2011 +0200 +++ b/ChangeLog Tue Jun 14 12:33:28 2011 +0200 @@ -1,3 +1,8 @@ +2011-06-14 Raimund Renkert <raimund.renkert@intevation.de> + + * src/java/de/intevation/mxd/ArcGISInitializer.java: + Load the arcobjects.jar from ArcGIS install folder. + 2011-06-10 Raimund Renkert <raimund.renkert@intevation.de> * src/java/de/intevation/mxd/ArcGISInitializer.java:
--- a/src/java/de/intevation/mxd/ArcGISInitializer.java Fri Jun 10 14:04:03 2011 +0200 +++ b/src/java/de/intevation/mxd/ArcGISInitializer.java Tue Jun 14 12:33:28 2011 +0200 @@ -2,6 +2,9 @@ import java.io.IOException; import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; import org.apache.log4j.Logger; @@ -35,22 +38,51 @@ public boolean initArcGIS () throws IOException { logger.debug("initArcGIS()"); - EngineInitializer.initializeEngine(); - aoInit = new AoInitialize(); - engineInstallDir = System.getenv("AGSENGINEJAVA"); - File installDir = new File(engineInstallDir); - if(!installDir.exists()) { + + String engineInstallDir = System.getenv("AGSENGINEJAVA"); + if(engineInstallDir == null) { engineInstallDir = System.getenv("AGSDESKTOPJAVA"); - installDir = new File(engineInstallDir); - if(!installDir.exists()) { + if(engineInstallDir == null) { logger.error("Could not find ArcGIS Environment. \n" + "AGSENGINEJAVA or AGSDESKTOPJAVA not set."); - return false; - } + return false; + } + } + + //Obtain the relative path to the arcobjects.jar file + String jarPath = engineInstallDir + "java" + File.separator + "lib" + + File.separator + "arcobjects.jar"; + + //Create a new file + File jarFile = new File(jarPath); + + //Test for file existence + if(!jarFile.exists()){ + logger.error("The arcobjects.jar was not found in the following location: " + + jarFile.getParent()); + logger.error("Verify that arcobjects.jar can be located in the specified folder."); + logger.error("If not present, try uninstalling your ArcGIS software and reinstalling it."); + System.exit(0); } - else { - return true; + + //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(); + logger.error("Could not add arcobjects.jar to system classloader"); + System.exit(0); + } + + EngineInitializer.initializeEngine(); + + aoInit = new AoInitialize(); return true; }