Java Directory Watcher

Watch and receive notifications on filesystem changes using Java 7 NIO's WatchService

License

License

GroupId

GroupId

com.darylteo
ArtifactId

ArtifactId

directory-watcher
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Java Directory Watcher
Watch and receive notifications on filesystem changes using Java 7 NIO's WatchService
Project URL

Project URL

http://github.com/darylteo/directory-watcher
Source Code Management

Source Code Management

http://github.com/darylteo/directory-watcher

Download directory-watcher

How to add to project

<!-- https://jarcasting.com/artifacts/com.darylteo/directory-watcher/ -->
<dependency>
    <groupId>com.darylteo</groupId>
    <artifactId>directory-watcher</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.darylteo/directory-watcher/
implementation 'com.darylteo:directory-watcher:1.2.0'
// https://jarcasting.com/artifacts/com.darylteo/directory-watcher/
implementation ("com.darylteo:directory-watcher:1.2.0")
'com.darylteo:directory-watcher:jar:1.2.0'
<dependency org="com.darylteo" name="directory-watcher" rev="1.2.0">
  <artifact name="directory-watcher" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.darylteo', module='directory-watcher', version='1.2.0')
)
libraryDependencies += "com.darylteo" % "directory-watcher" % "1.2.0"
[com.darylteo/directory-watcher "1.2.0"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.+

Project Modules

There are no modules declared in this project.

Directory Watcher for Java 7

Watches for changes in files and folders recursively. Features Ant style filtering patterns.

Distribution

Maven

<dependency>
  <groupId>com.darylteo</groupId>
  <artifactId>directory-watcher</artifactId>
  <version>1.2.0</version>
</dependency>

Gradle

dependencies {
  compile 'com.darylteo~directory-watcher~1.2.0'
}

Example

public class Example {
  public static void main(String[] args) {
    // Get Watcher
    ThreadPoolDirectoryWatchService factory = new ThreadPoolDirectoryWatchService(); // or PollingDirectoryWatchService
    DirectoryWatcher watcher = factory.newWatcher("");
    
    // Configure 
    watcher.include("src/**");
    watcher.exclude("bin");
    watcher.exclude("build");
    watcher.exclude("bin/**");
    watcher.exclude("build/**");
    
    // Subscribe
    watcher.subscribe(new DirectoryChangedSubscriber() {
      public void directoryChanged(DirectoryWatcher watcher, Path path) {
        System.out.println("Something changed! " + path.toString());
      }
    });
    
    // Cleanup
    factory.close();
  }
}

Documentation

Javadoc

Versions

Version
1.2.0
1.1.1