Through PathHelper we can resolve or collect paths or retrieving resources even through supported archive files (zip, jar, jmod, ear and war). In order to accomplish the task, we initially need to add the following dependency to our pom.xml:
<dependency> <groupId>org.burningwave</groupId> <artifactId>core</artifactId> <version>12.64.3</version> </dependency>
… And to use Burningwave Core as a Java module, add the following to your module-info.java
:
requires org.burningwave.core;
So we can create a path collection by adding an entry in burningwave.properties file that starts with ‘paths.’ prefix (this is a fundamental requirement to allow PathHelper to load the paths), e.g.:
paths.my-collection=c:/some folder;C:/some folder 2/ some folder 3; paths.my-collection-2=c:/some folder 4;C:/some folder 6;
These paths could be retrieved through PathHelper.getPaths method and we can find a resource in all configured paths plus the runtime class paths (that is automatically loaded under the entry named ‘paths.main-class-paths’) by using PathHelper.getResource method, e.g.:
ComponentSupplier componentSupplier = ComponentContainer.getInstance(); PathHelper pathHelper = componentSupplier.getPathHelper(); Collection<String> paths = pathHelper.getPaths("paths.my-collection", "paths.my-collection-2")); //With the code below all configured paths plus runtime class paths will be iterated to search //the resource called some.jar FileSystemItem resource = pathHelper.getResource("/../some.jar"); InputStream inputStream = resource.toInputStream();
We can also use placeholder and relative paths, e.g.:
paths.my-collection-3=C:/some folder 2/ some folder 3; paths.my-jar=${paths.my-collection-3}/../some.jar;
It is also possibile to obtain references to resources of the runtime class paths by using the pre-loaded entry ‘paths.main-class-paths’ (runtime class paths are automatically iterated for searching the path that match the entry), e.g.:
paths.my-jar=${paths.main-class-paths}/../some.jar;
We can also use a FileSystemItem listing (FSIL) expression and, for example, create a path collection of all absolute path of all classes of the runtime class paths:
paths.all-runtime-classes=//${paths.main-class-paths}//allChildren:.*?\.classes;
A FSIL expression encloses in a couple of double slash an absolute path or a placeholdered path collection that will be scanned; after the second double slash we have the listing type that could refear to direct children of scanned paths (‘children‘) or to all nested children of scanned paths (‘allChildren‘); after that and colons we have the regular expression with we are going to filter the absolute paths iterated.
BackgroundExecutor
ClassFactory
ClassHunter
- In depth look to and configuration guide
- USE CASE: how to retrieve all classes of the classpath
- USE CASE: how to retrieve all classes that implement one or more interfaces
- USE CASE: finding all classes that extend a base class
- USE CASE: how to find all classes in a package
- USE CASE: Finding all classes for module name (Java 9 and later)
- USE CASE: finding all annotated classes
- USE CASE: how to scan classes for specific annotations and collect their values
- USE CASE: how to search for all classes with a constructor that takes a specific type as first parameter and with at least 2 methods that begin for a given string
- USE CASE: how to search for all classes with methods whose name begins for a given string and that takes a specific type as its first parameter
- USE CASE: finding all classes that have at least 2 protected fields
ClassPathHunter
CodeExecutor
FileSystemItem
FunctionalInterfaceFactory
IterableObjectHelper
JavaMemoryCompiler
PropertyAccessor
UnitSourceGenerator