我无法保持 vfs2 的 DefaultFileMonitor 线程处于活动状态。在监视器对象启动后,执行的主线程会优雅地终止。我想知道为什么这个对象不会被“监控”,而是直接走到最后。(以日志消息“exitting....”结尾)
public static void main(String[] args) {
try {
Options options = new Options();
options.addOption("b", true, "path to the build file");
options.addOption("d", true, "directory to watch");
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
String dir = cmd.getOptionValue("d");
String buildFile = cmd.getOptionValue("b");
if(dir == null) {
logger.error("No directory specified," +
" use [-d 'name_of_dir'] to specify one");
return;
}
if(buildFile == null) {
logger.error("No build file path specified," +
" use [-b 'path_to_build_file'] to specify one");
return;
}
FileSystemManager fsManager = VFS.getManager();
FileObject listendir = fsManager.resolveFile(dir);
DefaultFileMonitor fm = new DefaultFileMonitor(new CustomFileListener(buildFile));
fm.setRecursive(true);
fm.addFile(listendir);
fm.start();
}catch(Exception e){
logger.error("Exception ", e);
}
logger.info("exitting....");
}