我正在尝试实施JNotify。但是当我编译程序时,我得到了一些奇怪的错误消息。我从这个站点获取示例代码ttp://jnotify.sourceforge.net/sample.html
作为信息,JNotify用于目录监控,这就是我的源代码的样子。
这是watch.java类的内容
import net.contentobjects.jnotify.JNotifyListener;
import net.contentobjects.jnotify.JNotify;
public class watching{
public void watching(String s) throws Exception {
// path to watch
String path = System.getProperty(s);
// watch mask, specify events you care about,
// or JNotify.FILE_ANY for all events.
int mask = JNotify.FILE_CREATED |
JNotify.FILE_DELETED |
JNotify.FILE_MODIFIED |
JNotify.FILE_RENAMED;
// watch subtree?
boolean watchSubtree = true;
// add actual watch
int watchID = JNotify.addWatch(path, mask, watchSubtree, new Listener());
// sleep a little, the application will exit if you
// don't (watching is asynchronous), depending on your
// application, this may not be required
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 fileRenamed(int wd, String rootPath, String oldName,
String newName) {
print("renamed " + rootPath + " : " + oldName + " -> " + newName);
}
public void fileModified(int wd, String rootPath, String name) {
print("modified " + rootPath + " : " + name);
}
public void fileDeleted(int wd, String rootPath, String name) {
print("deleted " + rootPath + " : " + name);
}
public void fileCreated(int wd, String rootPath, String name) {
print("created " + rootPath + " : " + name);
}
void print(String msg) {
System.err.println(msg);
}
}
}
然后这是名为nowwatch.java的主类
public class nowwatch
{
public static void main(String[] args) throws Exception
{
System.out.println("Hello World!");
watching hello = new watching();
hello.watching("C:/Users/Raden/Documents/Downloads");
}
}
但为什么错误会像这样?我已截屏错误,因此您可以点击此link
查看错误你们有没有遇到过这种错误?任何帮助将不胜感激。 感谢
答案 0 :(得分:2)
JNotify肯定使用JNI与依赖于操作系统的通知API进行交互。看起来JNotify中有一个错误。您是否尝试过在SourceForge上的JNotify论坛上询问?
答案 1 :(得分:0)
我们遇到了同样的问题。因为我们还是使用了JNA,所以我们只使用了这个框架中的FileMonitor示例。像魅力一样。
答案 2 :(得分:0)
它要求提供jNotify.dll文件,确保已将该文件放在窗口或jre / bin或jdk / bin中。然后尝试它将开始工作。