从这里获得最新版本http://code.google.com/p/inotify-java/,并参考下面的安装手册
注意,当前版本号是0.1,所以[version]都要换成0.1
并且还需要设置环境变量JAVA_HOME,可以只在编译用的终端设置
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.15/
要先安装过ant,然后进入解压后的目录,使用如下命令编译:
chenshu@chenshu-desktop:~/work/inotify-java-0.1$ ant release -Dversion=0.1
然后拷贝已经编译出来的动态库到/usr/lib目录中
sudo cp build/native/libinotify-java.so /usr/lib
sudo cp dist/inotify-java-0.1.jar /usr/share/java/
配置NetBeans6.7.1,添加一个inotify库,如下图设置:
环境已经准备好了。
现在新建一个JavaApplication工程inotifyTest,然后将inotify库加入。示例代码如下:
package inotifytest;
import com.den_4.inotify_java.Constants;
import com.den_4.inotify_java.EventQueueFull;
import com.den_4.inotify_java.Inotify;
import com.den_4.inotify_java.InotifyEvent;
import com.den_4.inotify_java.InotifyEventListener;
import com.den_4.inotify_java.InsufficientKernelMemoryException;
import com.den_4.inotify_java.SystemLimitException;
import com.den_4.inotify_java.UserLimitException;
public class Main {
public static void main(String[] args){
try {
Inotify i = new Inotify();
InotifyEventListener e = new InotifyEventListener() {
@Override
public void filesystemEventOccurred(InotifyEvent e) {
System.out.println("inotify event occurred!");
System.out.println("Name:"+e.getName());
System.out.println("Mask:"+Integer.toHexString(e.getMask()));
System.out.println("Mask:"+e.toString());
}
@Override
public void queueFull(EventQueueFull e) {
System.out.println("inotify event queue: " + e.getSource() +
" is full!");
}
};
i.addInotifyEventListener(e);
i.addWatch("/home/chenshu/", Constants.IN_ALL_EVENTS);
} catch (UnsatisfiedLinkError e) {
System.err.println("unsatisfied link error");
} catch (UserLimitException e) {
System.err.println("user limit exception");
} catch (SystemLimitException e) {
System.err.println("system limit exception");
} catch (InsufficientKernelMemoryException e) {
System.err.println("insufficient kernel memory exception");
}
}
}
注意,该程序无法自动结束。关掉NetBeans或者kill的方式可以结束掉。
分享到:
相关推荐
第一步:把ubuntu-9.10-desktop-i386.iso 文件拷贝到非安装盘,比如D盘。 第二步:用UltraISO(或解压缩)把ubuntu-9.10-desktop-i386.iso里casper目录下的initrd.lz和vmlinuz两个文件提取出来放到D盘根目录下。 第...
ubuntu9.10的用户指南汉化包,deb格式.
很详细的 Ubuntu 9.10 图解安装教程
Win 7 与 Ubuntu9.10系统安装顺序 (1)Win7 (2)Ubuntu9.10,注意在安装步骤第7步的时候,点击高级按钮,选择安装启动器引导设备的位置为你手动分区的那个光盘。 (3)登录win7(此时系统直接进入win7的),将此...
ubuntu910界面汉化安装包,deb格式。由于包的相互依赖,需用如下命令安装: #dpkg -i language-pack-gnome-zh-hans_1%3a9.10+20091022_all.deb language-pack-gnome-zh-hans-base_1%3a9.10+20091022_all.deb #dpkg -...
ubuntu 智能拼音安装方法(个人比较中意这个输入法)
ubuntu9.10的源,用于更新; Archive.ubuntu.com更新服务器(欧洲,此为官方源,电信网通用户使用): deb http://archive.ubuntu.com/ubuntu/ karmic main restricted universe multiverse deb ...
ubuntu910的ibus输入法,由于附件大小的限制,分开成两个资源上传.
硬盘安装 windows 7 和 ubuntu 9.10 双系统 Windows 7 和 ubuntu 都已经发布了,想体验一下。 Windows 7 已经安装了,本来想用 wubi 安装 ubuntu ,担心 ubuntu 系统性能不好,使用虚拟机安装吧,也是担心同样的...
eclipse3.6+ubuntu9.10配色方案 eclipse3.6+ubuntu9.10配色方案 eclipse3.6+ubuntu9.10配色方案
ubuntu 9.10网易最快的源 ubuntu 9.10网易最快的源
安装 Ubuntu 9.10 全过程视频教程
ubuntu 9.10更新源(速度最快的) ubuntu 9.10更新源(速度最快的) ubuntu 9.10更新源(速度最快的) ubuntu 9.10更新源(速度最快的)
步骤很详细,我本人已经安装成功,初次安装的新手,找上面的操作,保证OK!
用虚拟机在移动硬盘上安装Ubuntu 9.10 视屏
Ubuntu 9.10 安装 Mediawiki 脚本
Ubuntu icons svg files Ubuntu9.10
Ubuntu 9.10 拨号错误解决方法
ubuntu9.10上openoffice界面的汉化包,deb格式.
Ubuntu 9.10安装Oracle 10g手记