Reputation: 4815
I am using JNotify library in my java program to keep monitoring Directory for new file creation. I have added jar file in project library. And it looks like it was refering to some .dll filw which I got while downloading jar file. So I loaded dll file in my program using following line:
System.load("D:\\LEADER\\libraries\\jnotify\\jnotify_64bit.dll");
But I am getting following exception:
Error loading library, java.library.path=C:\Program Files\Java\jdk1.7.0_79\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_71/bin/server;C:/Program Files/Java/jre1.8.0_71/bin;C:/Program Files/Java/jre1.8.0_71/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\gcc\bin;C:\gcc\libexec\gcc\x86_64-pc-mingw32\5.1.0;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_79\bin;D:\softwares\apache-tomcat-7.0.57\bin\;D:\softwares\apache-maven-3.2.5\bin;C:\Program Files\MongoDB\Server\3.0\bin;C:\PROGRA~2\Groovy\GROOVY~1.5\bin;D:\LEADER\libraries;C:\Program Files\SQL Anywhere 12\bin64;C:\Program Files\SQL Anywhere 12\bin32;C:\Program Files (x86)\Sybase\Shared\PowerBuilder;C:\Program Files (x86)\Sybase\PowerBuilder 12.5;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files (x86)\Applied Information Sciences\UA10R3\dll;C:\Program Files (x86)\Mercurial;C:\Program Files\WinRAR;D:\softwares\eclipse;;.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnotify_64bit in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1088)
at net.contentobjects.jnotify.win32.JNotify_win32.<clinit>(Unknown Source)
at net.contentobjects.jnotify.win32.JNotifyAdapterWin32.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:379)
at net.contentobjects.jnotify.JNotify.<clinit>(Unknown Source)
at com.unisys.practice.JNotifyTest.sample(JNotifyTest.java:22)
at com.unisys.practice.JNotifyTest.main(JNotifyTest.java:61)
Here below I mentioned part of code:
.....
public void sample() throws Exception {
System.load("D:\\LEADER\\libraries\\jnotify\\jnotify_64bit.dll");
// path to watch
String path = "C:\\Users\\DadMadhR\\Desktop\\temp\\";
int mask = JNotify.FILE_CREATED;
boolean watchSubtree = true;
int watchID = JNotify.addWatch(path, mask, watchSubtree, (JNotifyListener) new Listener());
Thread.sleep(1000000);
// to remove watch the watch
boolean res = JNotify.removeWatch(watchID);
if (!res) {
// invalid watch ID specified.
}
}
class Listener implements JNotifyListener {
public void fileCreated(int wd, String rootPath, String name) {
print("created " + rootPath + " : " + name);
}
// other unimplemented methods
}
....
I tried to set the path variable to the folder where jar file and dll file resides and run program again. But I am getting same error. Can someone help me to figure it out why am I getting this exception?
Upvotes: 1
Views: 1553
Reputation: 4815
I added required .dll file in the path "C:\Program Files\Java\jdk1.7.0_79\bin\" and run program again. So it's working fine.
Upvotes: 3