feat(mon_dir): initial commit

This commit is contained in:
dancingCycle 2021-11-23 12:20:40 -05:00
parent 987c14eb56
commit a22078bc17
4 changed files with 166 additions and 0 deletions

31
mon_dir/.gitignore vendored Normal file
View File

@ -0,0 +1,31 @@
# Files
.classpath
.externalToolBuilders
.gradle
.project
.pydevproject
.settings
.sonar
*~
*.ipr
*.iml
*.iws
*.swp
*.DS_Store
*.snap.debug
dependency-reduced-pom.xml
# Directories
.idea/
.run/
.venv/
_site/
build/
dist/
docs/_build/
gen-java/
gen-javabean/
gen-py/
node_modules/
target/

5
mon_dir/README.md Normal file
View File

@ -0,0 +1,5 @@
# Overview
This project can serve as starting point for Maven and Java based projects.
# Links
[source](https://javapapers.com/core-java/monitor-a-folder-using-java/)

86
mon_dir/pom.xml Normal file
View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>mon_dir</name>
<description>description</description>
<url>https://swingbe.de</url>
<groupId>org.swingbe.de</groupId>
<artifactId>mon_dir</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<licenses>
<license>
<name>GNU General Public License</name>
<url>https://www.gnu.org/licenses/gpl-3.0.txt</url>
</license>
</licenses>
<scm>
<url>https://github.com/Software-Ingenieur-Begerad/sandbox-java</url>
</scm>
<properties>
<!-- Other properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- Target Java versions -->
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<!-- exclude signatures from merged JAR to avoid invalid signature messages -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<!-- The shaded JAR will not be the main artifact for the project, it will be attached
for deployment in the way source and docs are. -->
<shadedArtifactAttached>true
</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>de.swingbe.mon_dir.Main
</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,44 @@
package de.swingbe.mon_dir;
import java.io.IOException;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws IOException,
InterruptedException {
Path folder = Paths.get("./");
//obtain WatchService instance using FileSystems class
WatchService watchService = FileSystems.getDefault().newWatchService();
//register path to be watched with this instance
folder.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
boolean valid = true;
do {
WatchKey watchKey = watchService.take();
for (WatchEvent event : watchKey.pollEvents()) {
WatchEvent.Kind kind = event.kind();
if (StandardWatchEventKinds.ENTRY_CREATE.equals(event.kind())) {
String fileName = event.context().toString();
System.out.println("File Created:" + fileName);
} else if (StandardWatchEventKinds.ENTRY_MODIFY.equals(event.kind())) {
String fileName = event.context().toString();
System.out.println("File modified:" + fileName);
} else if (StandardWatchEventKinds.ENTRY_DELETE.equals(event.kind())) {
String fileName = event.context().toString();
System.out.println("File deleted:" + fileName);
} else {
System.out.println("Event unkown");
}
valid = watchKey.reset();
}
}
while (valid);
}
}