In this article let’s take a look at how to find all classes of a package in Java
To find all classes of a package in Java we can use the ClassHunter of Burningwave Core library. So we start by adding the following dependency to our pom.xml:
XML
1
<dependency>2
<groupId>org.burningwave</groupId>3
<artifactId>core</artifactId>4
<version>8.4.0</version>5
</dependency>
The next steps are the following:
- retrieving the ClassHunter through the ComponentContainer
- defining a regular expression that we must pass to the **ClassCriteria **object that will be injected into the **SearchConfig **object
- calling the **loadInCache **method that loads in the cache all loadable classes of the indicated paths, then applies the criteria filter and then returns the **SearchResult **object which contains the classes that match the criteria
#java #classes #class #packages #package #how to find all the classes of a package in java