Note
I’m not loading a .jar library, I’m only loading a .class, which implements my library functions. To test this code you must have in the directory D:\LoadLibrary a TestHelloWorld.class and the interface TestString WITH THE SAME package that you have in the main code. It means that if your TestString in your main code is com.haduart.TestString you must put your TestString.class in the D:\LoadLibrary\com\haduart\TestString.class.
-
/**
-
* In the D:/LoadLibrary we must have .class and the same interface (TestString) with the same pacakge as the
-
* main program.
-
*/
-
Class c2 = cl.loadClass(“TestHelloWorld”);
-
TestString ts = (TestString) cons.newInstance(args);
-
/**
-
* Now we can use the “ts” object as a normal TestString interface. No matter which is the implementation that is begin it.
-
*/