lundi 13 juillet 2020

Have Implementation in Classpath code to be used in Library

I am trying to write a Utility library (jar),

Inside Library

interface ConfigBuilder
{
  public Configuration buildConfiguration()
}

class SomeLogic
{
  private void someMethod()
  {
    ConfigBuilder  builder = // GET IMPLEMETATION OBJECT FROM IMPLEMENTOR OF LIBRARY ??
    Configuration c = builder.buildConfiguration();
    method2(c)
    //Some logic
  }
}

How can I do this ?? I am using Gradle as build tool. As being library We don't have an implementation class. Max we can do is - Who ever is implementing this library create a class with name com.xyz.lib.implimentation.ConfigBuilderImpl

implementing ConfigBuilder Interface

What I tried I was

this.getClass.getClassLoader.loadClass("com.xyz.lib.implimentation.ConfigBuilderImpl")

Then I am getting Exception

java.lang.ClassNotFoundException: com.xyz.lib.implimentation.ConfigBuilderImpl
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)




Aucun commentaire:

Enregistrer un commentaire