Scanndal

Scanndal is a scala library, which enables software developers to scan the classpath for classes without loading them via a classloader.

View the Project on GitHub ouven/scanndal

Main design goal:

Having no transient maven dependencies, except the scala-library.

Most libraries of this kind utilize an opcode engineering library like asm, bcel or javaassist and any logging tool and other frameworks. The most common case, I used classpath scanning was, when I wrote some kind of runners, which bring their own dependencies into the pool, so solving version clashes became daily business.

The library is highly influenced by ronmamos reflections library at googlecode (https://code.google.com/p/reflections/) and the apache bcel project.

Purpose

Scanndal enables software developers to scan the classpath for classes without loading them. This can be necessary, if you have to look for all classes in your classpath, that match certain attributes.

For example, if you were writing a servlet container for the servlet api 3.1 and you need to find all classes, that are annotated with the @WebServlet annotation. If you would use the reflection api, you would have to load all classes in your classpath, before you could check if it is annotated or not. That would waste a lot of permgen space and all static parts in a class would be executed, which could lead to unwanted site effects. Scanndal goes an other way and analyses the class file bytes to find your matches, so only the heap is littered and nothing is executed.

The example mentioned above would be implemented like that:

// results in a List[Class[HttpServlet]]
val servlets = Scanndal("my.root.package").scan
   .filter(new ClassAnnotationFilter[WebServlet]())
   .map(new ClassMapper[HttpServlet])
   .toList

Latest release

Scanndal is available in the maven central repository. For details see the README file.