我在Java程序中使用JNotify库来继续监视Directory以创建新文件。我在项目库中添加了jar文件。看来它是指我在下载jar文件时获得的.dll filw。因此,我使用以下行在程序中加载了dll文件:
System.load("D:\\LEADER\\libraries\\jnotify\\jnotify_64bit.dll");
但是我收到以下异常:
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)
在下面,我提到了部分代码:
.....
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
}
....
我试图将路径变量设置为jar文件和dll文件所在的文件夹,然后再次运行程序。但是我遇到了同样的错误。有人可以帮我弄清楚为什么我会得到这个例外吗?
我在路径“ C:\ Program Files \ Java \ jdk1.7.0_79 \ bin \”中添加了所需的.dll文件,然后再次运行程序。这样就可以了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句