2016-02-19 106 views
1

我在我的java程序中使用JNotify库来监视Directory以创建新文件。我已经在项目库中添加了jar文件。它看起来像是在下载jar文件时得到的一些.dll文件。所以,我用下面的行加载的DLL文件在我的计划:在使用JNotify时在线程“main”java.lang.UnsatisfiedLinkError中获取异常

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文件所在的文件夹,然后再次运行程序。但我得到同样的错误。 有人可以帮我弄清楚为什么我会得到这个异常?

+0

你可以发布你的jar和dll的绝对路径吗? – SomeDude

+0

你的代码有'System.load()',而你的堆栈跟踪显示'System.loadLibrary()'。确保附上正确的堆栈跟踪 - 代码对。 – diginoise

+0

@svasa我在System.load()中提到了dll的路径。并且jNotify.jar被添加为来自eclipse项目的外部jar。 – Madhusudan

回答

3

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

相关问题