Hi,
I wrote in Java code my own function to load a library module, the path should start with "/". In some class that is loaded the first I added items:
Code:
static Hashtable<String, String> charMaps = new Hashtable<String, String>();
Code:
static{
charMaps.put("%20", " ");
charMaps.put("%21", "!");
charMaps.put("%22", "\"");
charMaps.put("%23", "#");
charMaps.put("%24", "$");
charMaps.put("%25", "%");
charMaps.put("%26", "&");
charMaps.put("%27", "'");
charMaps.put("%28", "(");
charMaps.put("%29", ")");
charMaps.put("%2A", "*");
charMaps.put("%2B", "+");
charMaps.put("%2C", ",");
charMaps.put("%2D", "-");
charMaps.put("%2E", ".");
charMaps.put("%3B", ";");
charMaps.put("%3C", "<");
charMaps.put("%3D", "=");
charMaps.put("%3E", ">");
charMaps.put("%40", "?");
charMaps.put("%41", "@");
charMaps.put("%5E", "^");
charMaps.put("%60", "_");
charMaps.put("%7B", "{");
charMaps.put("%7C", "|");
charMaps.put("%7D", "}");
charMaps.put("%7E", "~");
}
Code:
public static void loadLibrary(String libName) {
String separator = java.io.File.separator;
String osName = System.getProperty("os.name");
String location = null;
String hardLib = System.getProperty("my.natives.libpath");
libName = libName == null ? System
.getProperty("com.compose.natives.lib") : libName;
String libExt = osName.indexOf("Windows") == -1 ? "" : ".dll";
if(hardLib != null && hardLib.length() > 0){
location = hardLib;
if(location.lastIndexOf(libName + libExt) == -1){
if(location.lastIndexOf(separator) != location.length() - 1
&& location.lastIndexOf(separator) != location.length() - 1)
location += separator;
if(location.length() < libName.length() + libExt.length()
|| location.substring(
location.length() - libName.length()
- libExt.length()).compareTo(
libName + libExt) != 0)
location += libName + libExt;
}
} else{
java.net.URL url = CNativeLibrary.class.getProtectionDomain()
.getCodeSource().getLocation();
location = new java.io.File(url.getFile()).getPath();
Enumeration<String> enumer = charMaps.keys();
while (enumer.hasMoreElements()){
String s = enumer.nextElement();
location = location.replaceAll(s, charMaps.get(s));
}
int extInd = location.lastIndexOf(".");
if(extInd != -1
&& location.substring(extInd).equalsIgnoreCase(".jar")){
int ind = location.lastIndexOf(separator);
if(ind > 0 && ind + 1 < location.length())
location = location.substring(0, ind + 1);
else
location = location.substring(0);
}
if(location.length() > 0
&& !location.substring(location.length() - 1).equals(
separator))
location += separator;
libName = location + libName;
location = libName + libExt;
}
if(location.charAt(0) != '/')
location = '/' + location;
if(location != null){
try{
Runtime.getRuntime().load(location);
} catch(RuntimeException e){
System.err.println("Cannot load \"" + libName + libExt
+ "\" from path " + location);
}
}
}
This code tries to find the native library by
- path of the class where these module added;
- my property "my.natives.libpath" initialized on start.
If your problem persists then check the library module function signatures exprorted, in Windows they should start with underscore.