Muss mich gerade erstmals mit JNI rumschlagen, damit ich einige meiner Logfiles mit JNotify (siehe http://jnotify.sourceforge.net/ )überwachen kann.
Ich lade die notwendige .so wie folgt:
das läuft auch richtig durch, ich nehme also an, dass die .so mit System.load korrekt geladen wurde.
java.library.path sieht anschließend so aus:
Versuche ich jetzt allerdings die erste watch anzulegen:
bekomme ich folgende Exception (zeile 49 ist oben per Kommentar markiert):
hier sieht es dann wieder so aus als wäre der Path nicht richtig gesetzt, was ja aber nicht sein kann, weil ja oben die lib richtig geladen werden kann. Was habe ich da übersehen?
Ich lade die notwendige .so wie folgt:
Code:
String workingPath = System.getProperty("user.dir");
String libpath = System.getProperty("java.library.path") + ":" + workingPath + "/src/nativeLibs";
System.out.println(libpath);
System.setProperty("java.library.path", libpath);
//JNotify Library Linux - Windows
if (System.getProperties().getProperty("os.name").contains("Linux")) {
System.load(workingPath + "/src/nativeLibs/libjnotify.so");
// System.loadLibrary("libjnotify");
} else if (System.getProperties().getProperty("os.name").contains("Windows")) {
System.load(workingPath + "/src/nativeLibs/jnotify.dll");
} else {
System.err.println("OS is not supported");
System.exit(0);
}
das läuft auch richtig durch, ich nehme also an, dass die .so mit System.load korrekt geladen wurde.
java.library.path sieht anschließend so aus:
/usr/lib/jvm/java-6-sun-1.6.0.03/jre/lib/i386/client:/usr/lib/jvm/java-6-sun-1.6.0.03/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.03/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib:/home/Joker/NetBeansProjects/logViewDaemon/src/nativeLibs
Versuche ich jetzt allerdings die erste watch anzulegen:
Code:
private void buildWatches() {
try {
for(LogFile file:config.getLogfiles()) {
if(checkFileRights(file.getPath())) {
JNotify.addWatch(file.getPath(), mask, false, fileListener); //Zeile 49
System.out.println("watch build ");
} else {
System.err.println("No rights for "+file.getPath());
}
}
} catch (JNotifyException jne) {
System.err.println("JNotifyException "+jne.getMessage());
jne.printStackTrace();
}
watching();
}
bekomme ich folgende Exception (zeile 49 ist oben per Kommentar markiert):
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnotify in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1030)
at net.contentobjects.jnotify.linux.JNotify_linux.<clinit>(Unknown Source)
at net.contentobjects.jnotify.linux.JNotifyAdapterLinux.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at net.contentobjects.jnotify.JNotify.<clinit>(Unknown Source)
at daemon.LogViewDaemon.buildWatches(LogViewDaemon.java:49)
at daemon.LogViewDaemon.<init>(LogViewDaemon.java:41)
at daemon.LogViewDaemon.main(LogViewDaemon.java:106)
Java Result: 1
hier sieht es dann wieder so aus als wäre der Path nicht richtig gesetzt, was ja aber nicht sein kann, weil ja oben die lib richtig geladen werden kann. Was habe ich da übersehen?