首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在linux中运行jnotify程序时出现异常

在linux中运行jnotify程序时出现异常
EN

Stack Overflow用户
提问于 2013-07-15 12:07:38
回答 1查看 3K关注 0票数 1

我一直在尝试在Fedora16上运行JNotify示例代码,代码如下:

代码语言:javascript
复制
import net.contentobjects.jnotify.JNotify;
import net.contentobjects.jnotify.JNotifyListener;
import net.contentobjects.jnotify.linux.JNotify_linux;
public class JNotifyDemo {

public void sample() throws Exception {
        // path to watch
        String path = System.getProperty("user.home");
        System.out.println(path);
        // watch mask, specify events you care about,
        // or JNotify.FILE_ANY for all events.
        int mask = JNotify_linux.IN_CREATE
                | JNotify_linux.IN_DELETE
                | JNotify_linux.IN_MODIFY
                | JNotify_linux.IN_ATTRIB;

        // 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) {
        // 
        // }
    }

    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);
        }
    }

    public static void main(String[] args) throws Exception {
        new JNotifyDemo().sample();
    }
}

这给我一个例外,如下所示:

代码语言:javascript
复制
/home/student Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnotify in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at net.contentobjects.jnotify.linux.JNotify_linux.<clinit>(Unknown Source)
at net.contentobjects.jnotify.linux.JNotifyAdapterLinux.<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:532)
at java.lang.Class.newInstance0(Class.java:374)
at java.lang.Class.newInstance(Class.java:327)
at net.contentobjects.jnotify.JNotify.<clinit>(Unknown Source)
at test.JNotifyDemo.sample(JNotifyDemo.java:29)
at test.JNotifyDemo.main(JNotifyDemo.java:67)

我已经按照其中一篇博客中的说明设置了libjnotify.so的路径,但我仍然得到由我设置的这个错误路径如下:

代码语言:javascript
复制
export PATH=${PATH}:/home/student/workspace/Google_Project/jnotify-lib-0.94/64-bit_Linux/
EN

回答 1

Stack Overflow用户

发布于 2013-12-06 19:19:43

http://www.coderanch.com/t/377174/java/java/java-library-path

环境变量名称是平台特定的

在Windows上设置路径

代码语言:javascript
复制
(don't actually remember how to set a windows env variable)    

在Linux上设置LD_LIBRARY_PATH

代码语言:javascript
复制
export LD_LIBRARY_PATH=jnotify-lib-0.94/64-bit_Linux/ 

在OSX上设置DYLD_LIBRARY_PATH

代码语言:javascript
复制
export DYLD_LIBRARY_PATH=/common/bryan_scratch/poc/poc_vips/project/src/.libs

为了避免这个问题,最好改用Java命令标志,因为它与平台无关,即

代码语言:javascript
复制
java -Djava.library.path=jnotify-lib-0.94/64-bit_Linux org.blah.MyMain
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17646624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档