2

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();
    }
wattostudios
  • 8,666
  • 13
  • 43
  • 57
Tushar Chutani
  • 1,522
  • 5
  • 27
  • 57

1 Answers1

4

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"
click on "build path"

Then select the library tab, under that click on "Add external jars"
Select :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

Rakesh
  • 4,264
  • 4
  • 32
  • 58
  • 1
    +1 Don't use an external jar, though. Better to place the jar in the project (or use Maven). – Thilo Aug 19 '11 at 05:56