Class ClassFileImporter


public final class ClassFileImporter
extends java.lang.Object
The central API to import JavaClasses from compiled Java class files. Supports various types of Location, e.g. Path, JarFile or URL. The Locations that are scanned can be filtered by passing any number of ImportOption to withImportOption(ImportOption), which will then be ANDed (compare ImportOptions).

Note that information about a class is only complete, if all necessary classes are imported. For example, if class A is imported, and A accesses class B, but class B is not imported, the import will behave according to the configured ClassResolver. With the default configuration, the importer will use the ClassResolverFromClasspath to attempt to import missing classes from the classpath, and by that complete any information necessary for rules. In the above case this would mean, if class A accesses B, but B is missing from the set of imported classes, the importer will try to locate the class on the classpath and then import that class, thus acquiring more information like superclasses and interfaces. However, it will not transitively go on to resolve access targets of these classes.

The resolution behavior, i.e. what the importer does if a class is missing from the context, can be configured by providing a respective ClassResolver. To use the simplest ClassResolver possible, namely one that does not import any further classes, simply configure
within your "".
Whenever the configured ClassResolver does not import a class, the importer will simply create a stub with all information known from the access, i.e. the fully qualified name of B and not much more. In particular the stub class B will miss any information like super classes, interfaces, etc.

In short, if one wants to write rules about certain properties of classes, it is important to ensure that all relevant classes are imported, even if those might be classes from the JDK (like RuntimeException or Exception).

For further information consult the ArchUnit user guide.
See Also: