Class loader library extend the possibility you now have with your dynamic object loading by locating a class not only by signature but also by interface, abstact, base class even annotation. You can even import jar not currently on your classpath. It was build for projects using a modular approach. You can use classes for what they provide without necessarily knowing their names.
- Locate classes from interface, abstract or base classes.
- Work on runtime class annotation too.
- Load jar dynamically at runtime from any directories.
- Build with an internal cache for fast access.
- Also provide some helper methods to introspect classes
- Read any informations from a class with RawClassDecoding
Sample code
This is just a snippet from the sample source code, see Download below
// locate all classes on classpath implementing SampleInterface.class, using default instance Class[] res = ClassFinder.getDefaultInstance().whoImplement(SampleInterface.class); // create a ClassLoader but restrict to a specific package for efficiency ClassFinder cl = new ClassFinder("vostokclasslibsample.sample"); // with annotation, it's the same... Class[] res = cl.whoImplement(MyAnnotation.class); // load all jar from a new location (directory) at runtime DynamicClassLoader dcl = DynamicClassLoader.newInstance(new File("/foo/bar")); // check for who's implementing MyInterface.class // Note signature, classes are not loaded yet String[] list = dcl.whoImplement(MyInterface.class); // create a new instance and casting it MyInterface my = dcl.newObjectInstance(MyInterface.class, list[0]);
RawClassDecoding was initially for internal use but can be useful too
// load by stream, can directly be an url InputStream stream = ClassFinder.getDefaultInstance().getClassLoader().getResourceAsStream("vostokclasslibsample/sample/raw/RawClassTesting.class"); RawClassDecoding decoding = new RawClassDecoding(stream); // obviously this is just for debug ! decoding.printDebug();
Install
VostokClassLib is made of a single jar weight 17.7Ko. Dependecies : VostokGlobLib and VostokIoLib
Download
- Download the jar : VostokClassLib-1.2.2.jar
- Download the javadocs : VostokClassLib-javadoc-1.2.2.tar.gz
- Download the sample source code (netbeans project) : VostokClassLibSample.tar.gz
Maven repository
A repository will be available soon
Javadocs
Licence
VostokClassLib is provided for free, for community, private or commercial work under the creative commons licence, CC-BY, no attribution needed.