From aa2cbaa89b9e5d5dfc8c5ddc00a5cfff44a4e713 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 16 Apr 2010 11:01:02 -0700 Subject: [PATCH] System.getenv throws Error in 1.4 jre --- .../java/src/org/hyperic/sigar/cmd/Runner.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bindings/java/src/org/hyperic/sigar/cmd/Runner.java b/bindings/java/src/org/hyperic/sigar/cmd/Runner.java index 9ae33474..ecb06707 100644 --- a/bindings/java/src/org/hyperic/sigar/cmd/Runner.java +++ b/bindings/java/src/org/hyperic/sigar/cmd/Runner.java @@ -31,6 +31,7 @@ import java.lang.reflect.InvocationTargetException; import java.net.URLClassLoader; import java.net.URL; +import org.hyperic.sigar.Sigar; import org.hyperic.sigar.SigarLoader; public class Runner { @@ -136,6 +137,21 @@ public class Runner { return !missingJars(); } + private static String getenv(String key) { + try { + return System.getenv("ANT_HOME"); //check for junit.jar + } catch (Error e) { + /*1.4*/ + Sigar sigar = new Sigar(); + try { + return sigar.getProcEnv("$$", "ANT_HOME"); + } catch (Exception se) { + return null; + } + finally { sigar.close(); } + } + } + public static void main(String[] args) throws Exception { if (args.length < 1) { args = new String[] { "Shell" }; @@ -184,7 +200,7 @@ public class Runner { } if (missingJars()) { - String home = System.getenv("ANT_HOME"); //check for junit.jar + String home = getenv("ANT_HOME"); //check for junit.jar if (home != null) { addJarDir(home + "/lib"); }