Registrar is a library for automatically discovering and loading Java classes on the classpath. Clients can optionally supply targeted search paths and class filters to control which classes are returned. Registrar borrows some of its internal search logic from the LCM library.
Registrar uses the Filter
interface to prune its search results. A Filter
accepts a class as input and then returns true if it should be included in the result. Clients can provide their own filter implementations, but some common ones are included in the library:
Filter.PASS
- Passes all classesFilter.FAIL
- Fails all classesTypeFilter
- Passes classes of a single typePackageFilter
- Passes classes in a single packageConjunctiveFilter
- Passes classes that pass all of a set of multiple filtersDisjunctiveFilter
- Passes classes that pass any of a set of multiple filters
Registrar only provides one basic function: finding classes on a given classpath. To find all classes on the default classpath (the Java execution classpath plus the contents of the CLASSPATH environment variable), use:
Set<Class<?>> classes = Registrar.find();
To find all classes on the default classpath that pass a given filter, use:
Filter filter = new TypeFilter(String.class);
Set<Class<?>> classes = Registrar.find(filter);
To find all classes on a particular classpath, use:
String classpath = "/path/to/jars";
Set<Class<?>> classes = Registrar.find(classpath);
To find all classes on a particular classpath that pass a given filter, use:
Filter filter = new TypeFilter(String.class);
String classpath = "/path/to/jars";
Set<Class<?>> classes = Registrar.find(filter, classpath);
Registrar is built with Maven. To build the project and install it in your local Maven repositiory, type:
mvn clean install
To include Registrar in another Maven project, add the following dependency to the project's pom.xml
:
<dependency>
<groupId>com.theisenp</groupId>
<artifactId>registrar</artifactId>
<version>(latest version)</version>
</dependency>
- Patrick Theisen - [email protected]
Copyright 2014 Patrick Theisen
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.