问题
I am getting an exception in my code saying org.apache.commons.vfs.* cannot be resolved. Could someone please explain why this is occurring, and how it can be fixed.
This is my code...
import org.apache.commons.vfs.FileChangeEvent;
import org.apache.commons.vfs.FileListener;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.VFS;
import org.apache.commons.vfs.impl.DefaultFileMonitor;
import com.sample.*;
public class watchDirectory implements FileListener{
public static void watchDir(String a){
FileSystemManager fsManager = VFS.getManager();
FileObject listendir = fsManager.resolveFile("/home/username/monitored/");
DefaultFileMonitor fm = new DefaultFileMonitor(new CustomFileListener());
fm.setRecursive(true);
fm.addFile(listendir);
fm.start();
}
回答1:
You are missing the library in your build path. Follow the steps to add the library into your project's build path
Right click on the project root, select "build path", under that select "configure build path"
Then select the library tab, under that click on "Add external jars"

Then browse for the jar file and add it to the build path, then refresh your project. If you don't have the jar file, you can download it from here
来源:https://stackoverflow.com/questions/7117343/cannot-resolve-package-org-apache-commons-vfs-exception