Posts

Showing posts from January, 2019

Recursively Move a Directory

recursively-move-a-directoryThis article shows one effective implementation that follows the Visitor Pattern to recursively move a directory using Java NIO library.publicstaticvoidmove(Path source, Path target)throws IOException {classFileMoverextendsSimpleFileVisitor<Path>{private Path source;private Path target;privateFileMover(Path source, Path target){this.source = source;this.target = target;}@Overridepublic FileVisitResult visitFile(final Path file,final BasicFileAttributes attrs)throws IOException { Path newFile = target.resolve(source.relativize(file)); Files.move(file, newFile, StandardCopyOption.REPLACE_EXISTING);return FileVisitResult.CONTINUE;}@Overridepublic FileVisitResult preVisitDirectory(final Path dir,final BasicFileAttributes attrs)throws IOException { Path newDir = target.resolve(source.relativize(dir));try{ Files.copy(dir, newDir, StandardCopyOption.COPY_ATTRIBUTES, …

Creating a Library Project for Spring Boot

creating-a-library-project-for-spring-bootThis article introduces the key points when creating a library for spring boot project.It could be common that over the years you have created a number of services that could be reused by other spring projects. It then makes sense to make the reusable modules such as a library and install it in your local repository for later use.Here are the key points to consider when building a spring boot library.release versionbuild plugindependency injectionautoconfigurationsRelease VersionTo guarantee spring boot works the way you expect, it is recommended to keep update the release versions of the library so that it supports some versions of the spring boot minor version. A good practice is to monitor change spring boot changelog and see if there are any conflicting dependencies that are used in the library project. If there is, introduce a new version to resolve the conflict.Build PluginIf the projects reference this library doesn’t compile through ma…