这段程序是找到jcurses.jar同目录下的 libjcurses.so库文件
仅供参考~~
也许有更简单的方法package jcurses.system;public class Toolkit {
static {
System.load(getLibraryPath());//加载动态连接库
}private static String getLibraryPath() {
String url = ClassLoader.getSystemClassLoader().getResource("jcurses/system/Toolkit.class").toString();//得出当前的类路径
url=url.trim();
if (url.startsWith("jar:file:")) {
url = url.substring("jar:file:".length(),url.length());
url = url.substring(0,url.length()-"/jcurses.jar!/jcurses/system/Toolkit.class".length());
} else if (url.startsWith("file:")) {
url = url.substring("file:".length(),url.length());
url = url.substring(0,url.length()-"/classes/jcurses/system/Toolkit.class".length());
url = new File(url,"lib").getAbsolutePath();
} else {
throw new RuntimeException("couldn't find jcurses library");
}
String [] fileNames = new File(url).list();
boolean found = false;
for (int i=0; i<fileNames.length; i++) {
String name = fileNames[i];
if (name.trim().startsWith("libjcurses")) {
url = new File(url,name).getAbsolutePath();
found = true;
break;
}
}
if (!found) {
throw new RuntimeException("couldn't find jcurses library");
}
return url;
}
}
要用单斜杠才行.