This is a patch against jRegistryKey 1.0 so that, if the DLL is not found in the PATH by the System.loadLibrary call, it looks through the CLASSPATH for it. --- RegistryKey.java.orig Thu Nov 1 16:21:58 2001 +++ RegistryKey.java Tue Nov 12 22:46:54 2002 @@ -27,6 +27,7 @@ */ package ca.beq.util.win32.registry; +import java.io.File; import java.util.Iterator; /** @@ -83,9 +84,48 @@ * @version 1.0 */ public class RegistryKey { - // loads the jRegistryKey(.dll) library (must be in the system PATH) + // loads the jRegistryKey(.dll) library from PATH or CLASSPATH static { - System.loadLibrary("jRegistryKey"); + try { + System.loadLibrary("jRegistryKey"); + } catch (UnsatisfiedLinkError ex) { + // didn't find it in our PATH, look for it in CLASSPATH + // Jim McBeath + String cp = System.getProperty("java.class.path"); + boolean foundIt = false; + while (cp.length() > 0) { + int x = cp.indexOf(File.pathSeparator); + String dir; + if (x >= 0) { + dir = cp.substring(0,x); + cp = cp.substring(x+1); + } else { + dir = cp; + cp = ""; + } + if (dir.length()>4 && + dir.substring(dir.length()-4).toLowerCase().equals(".jar")) { + // If the classpath contains a jar file, then we look in the + // directory containing the jar file. + x = dir.lastIndexOf(File.separator); + if (x>0) + dir = dir.substring(0,x); + else + dir = "."; + } + File f = new File(dir,"jRegistryKey.dll"); + if (f.exists()) { + String path = f.getAbsolutePath(); + System.load(path); // load JNI code + foundIt = true; + break; + } + } + if (!foundIt) { + // we did not find it in CLASSPATH + throw ex; // throw the can't-find-library exception + } + } } // static private RootKey root = RootKey.HKEY_CURRENT_USER; @@ -321,4 +361,4 @@ public String toString() { return (root.toString() + "\\" + this.path); } // toString() -} // RegistryKey \ No newline at end of file +} // RegistryKey