View: Loading a dinamic Library

  1. 9 months ago by haduart
    1. /**
    2. * In the D:/LoadLibrary we must have .class and the same interface (TestString) with the same pacakge as the
    3. * main program.
    4. */
    5. URL urlToJar = new URL("file://D:/LoadLibrary/");
    6. URLClassLoader cl = new URLClassLoader(new URL[] { urlToJar });
    7.                
    8. System.out.println("loading...");
    9. Class c2 = cl.loadClass("TestHelloWorld");
    10. System.out.println("loaded!");
    11. Object nouObject = c2.newInstance();
    12.  
    13. TestString ts = (TestString) cons.newInstance(args);
    14. /**
    15. * Now we can use the "ts" object as a normal TestString interface. No matter which is the implementation that is begin it.
    16. */
    17. System.out.println("S1: " + ts.printS1());
    18. System.out.println("S2: " + ts.printS2());

0 comment about "Loading a dinamic Library"