add getLocation method

This commit is contained in:
Doug MacEachern 2004-07-23 01:04:40 +00:00
parent e3e5ce3eb7
commit 530f6b9f2b
1 changed files with 18 additions and 0 deletions

View File

@ -1,11 +1,14 @@
package net.hyperic.sigar; package net.hyperic.sigar;
import net.hyperic.jni.ArchLoader; import net.hyperic.jni.ArchLoader;
import net.hyperic.jni.ArchLoaderException;
import net.hyperic.jni.ArchName; import net.hyperic.jni.ArchName;
import net.hyperic.jni.ArchNotSupportedException; import net.hyperic.jni.ArchNotSupportedException;
public class SigarLoader extends ArchLoader { public class SigarLoader extends ArchLoader {
private static String location = null;
public SigarLoader(Class loaderClass) { public SigarLoader(Class loaderClass) {
super(loaderClass); super(loaderClass);
} }
@ -34,4 +37,19 @@ public class SigarLoader extends ArchLoader {
protected void systemLoad(String name) { protected void systemLoad(String name) {
System.load(name); System.load(name);
} }
/**
* Returns the path where sigar.jar is located.
*/
public synchronized static String getLocation() {
if (location == null) {
SigarLoader loader = new SigarLoader(Sigar.class);
try {
location = loader.findJarPath("sigar.jar");
} catch (ArchLoaderException e) {
location = ".";
}
}
return location;
}
} }