changeset 112:82a220ac7033

Merged with Stephans commits.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 14 Jun 2011 12:46:35 +0200
parents 104af51a4717 (diff) 01cd6b736acd (current diff)
children 0db6eacad0e6
files ChangeLog
diffstat 2 files changed, 49 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/ArcGISInitializer.java:
+	  Load the arcobjects.jar from ArcGIS install folder.
+
 2011-06-14  Stephan Holl  <stephan.holl@intevation.de>
 
 	* 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.
 
--- 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<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;
     }
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)