# HG changeset patch # User Raimund Renkert # Date 1308048395 -7200 # Node ID 82a220ac70336ca95ab6d39a053f402eab2bf733 # Parent 104af51a47171b1f13c17e88290df33e38e2c933# Parent 01cd6b736acd02cee983d8c31edce99555f4fab3 Merged with Stephans commits. diff -r 01cd6b736acd -r 82a220ac7033 ChangeLog --- a/ChangeLog Tue Jun 14 12:40:37 2011 +0200 +++ b/ChangeLog Tue Jun 14 12:46:35 2011 +0200 @@ -1,3 +1,8 @@ +2011-06-14 Raimund Renkert + + * src/java/de/intevation/mxd/ArcGISInitializer.java: + Load the arcobjects.jar from ArcGIS install folder. + 2011-06-14 Stephan Holl * mapserver/mapfile/mxd.map: Added ows_enable_request-directive to @@ -12,6 +17,7 @@ * src/java/de/intevation/mxd/ArcGISInitializer.java: Check for ArcGISDesktop environment and added logging. + * src/java/de/intevation/mxd/reader/MXDReader.java: Check the initializer return value. diff -r 01cd6b736acd -r 82a220ac7033 src/java/de/intevation/mxd/ArcGISInitializer.java --- a/src/java/de/intevation/mxd/ArcGISInitializer.java Tue Jun 14 12:40:37 2011 +0200 +++ b/src/java/de/intevation/mxd/ArcGISInitializer.java Tue Jun 14 12:46:35 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 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; }