gpt4 book ai didi

java - 使用 JNotify 时在线程 "main"java.lang.UnsatisfiedLinkError 中获取异常

转载 作者:行者123 更新时间:2023-11-29 04:50:46 25 4
gpt4 key购买 nike

我在我的 java 程序中使用 JNotify 库来持续监控目录以创建新文件。我在项目库中添加了 jar 文件。看起来它指的是我在下载 jar 文件时得到的一些 .dll 文件。所以我使用以下行在我的程序中加载了 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文件所在的文件夹,然后再次运行程序。但我遇到了同样的错误。有人可以帮我弄清楚为什么我会收到这个异常(exception)吗?

最佳答案

我在路径“C:\Program Files\Java\jdk1.7.0_79\bin\”中添加了所需的.dll 文件并再次运行程序。所以它工作正常。

关于java - 使用 JNotify 时在线程 "main"java.lang.UnsatisfiedLinkError 中获取异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35505979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com