Load java jar files dynamically in isolated class loader to avoid dependency conflicts and enable modular updates. All jar files in the [main jar folder]/lib/myLib/2.0/*.jar will be loaded.
Visit my ITZap blog to read more about this project.
- Create Object from a JAR file located in the myLib/2.0 folder:
ProxyCallerInterface object = ObjectBuilder.builder()
.setPackageName("org.my.package")
.setClassName("MyClass")
.setVersionInfo(newVersionInfo("myLib", "2.0"))
.build();
object.call("objectMethod");
- Create object from factory method and pass "string param" and 1 to it:
ProxyCallerInterface object = ObjectBuilder.builder()
.setPackageName("org.my.package")
.setClassName("MyClass")
.setVersionInfo(newVersionInfo("myLib", "2.0"))
.setFactoryMethod("initMyClass")
.setParams("string param", 1)
.build();
- Object builder can implement proxy interface:
ProxyCallerInterface object = ObjectBuilder.builder()
.setClassName("org.mypackage.myclass")
.setVersionInfo(newVersionInfo("myLib", "2.0"))
.build();
// Example with call back
object.call("addListener", ObjectBuilder.from(builder)
.setInterfaceName("org.mypackage.MyListener")
.setHandler(new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// handle call back
return null;
})
.build()
- Instantiating object with constructor parameters
ProxyCallerInterface object = ObjectBuilder.builder()
.setPackageName("org.my.package")
.setClassName("MyClass")
.setVersionInfo(newVersionInfo("myLib", "2.0"))
.setParams("String param", 1)
.build();
- Loading Enums
Map<String, ProxyEnum> enum = ObjectBuilder.from(builder)
.setClassName("MyClass$USStates")
.buildEnum();
- Calling setters on a created object
List<MethodDesriptor> descriptors = Lists.newArrayList();
ObjectBuilder builder = ObjectBuilder.builder()
.setClassName("org.mypackage.MyClass")
.setParams("String param")
.setDescriptors(descriptors);
// call setter
descriptors.add(MethodDesriptor.method("setProperty", "property name", "value"));
ProxyCallerInterface object = builder.build();
- Calling static methods
List<MethodDesriptor> settings = Lists.newArrayList();
ObjectBuilder builder = ObjectBuilder.from(builder)
.setClassName("org.MyUtils")
.setStaticObject(true)
.setDescriptors(settings);
settings.add(MethodDesriptor.method("convert", "from this string"));
builder.build();