Note that there are some explanatory texts on larger screens.

plurals
  1. POWatch for changes to files Java
    primarykey
    data
    text
    <p>I'm trying to develop a watch service that, every time a piece of code is modifed, created or deleted, does a certain action.</p> <p>I've made a Daemon that implements WatchService and that gets the path to a certain package to watch, for example "../JDV/src/randompackage/java/test/money_scenario".</p> <p>This Daemon has the following code:</p> <pre><code>public Daemon(Path dir) throws IOException{ this.dir = dir; watcher = FileSystems.getDefault().newWatchService(); WatchKey key = dir.register(watcher, ENTRY_CREATE,ENTRY_DELETE, ENTRY_MODIFY); } public void processEvents() throws InitializationError { for (;;) { // wait for key to be signaled WatchKey key; try { key = watcher.take(); } catch (InterruptedException x) { return; } for (WatchEvent&lt;?&gt; event: key.pollEvents()) { WatchEvent.Kind kind = event.kind(); if (kind == OVERFLOW) { continue; } if(kind == ENTRY_CREATE) { System.out.println("Creation has been detected in " + getDirName()); } if(kind == ENTRY_DELETE) { System.out.println("Deletion has been detected in " + getDirName()); } if(kind == ENTRY_MODIFY) { System.out.println("Modification has been detected in " + getDirName()); } } boolean valid = key.reset(); if (!valid) { break; } } } </code></pre> <p>What happens is the following: I run the Daemon and it is active. Whenever I go Create or Delete a class in in the money_scenario package (which itselves has subpackages from where I could delete/create the class), the Daemon detects it and prints "Modification has been detected", instead of creation/deletion. When I modify a class in the money_scenario package, it doesn't detect anything.</p> <p>What am I doing wrong?</p> <p>Edit: Resolved but another issue popped up. Multiple events: When I delete a class for example I get:</p> <p>Modification has been detected in money_scenario Deletion has been detected in money_scenario Modification has been detected in money_scenario</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload