FileSystemManager fsManager = null;
FileObject listendir = null;
try {
fsManager = VFS.getManager();
listendir = fsManager.resolveFile(new File(
"./classes/").getAbsolutePath());
} catch (FileSystemException e) {
log.error("监视文件夹出错了", e);
e.printStackTrace();
}
DefaultFileMonitor fm = new DefaultFileMonitor(new FileListener() {
public void fileCreated(FileChangeEvent event) throws Exception {
monitor(event);
}
public void fileDeleted(FileChangeEvent event) throws Exception {
monitor(event);
}
public void fileChanged(FileChangeEvent event) throws Exception {
monitor(event);
}
private void monitor(FileChangeEvent event) {
FileObject fileObject = event.getFile();
FileName fileName = fileObject.getName();
if (fileName.getBaseName().endsWith(".class")) {
reload();
}
}
});
fm.setRecursive(true);
fm.addFile(listendir);
fm.start();