I have created a plugin application and need to pass multiple dependency Jars from a folder dynamically at runtime for JDBC connection.
When using single jar, works fine.,
try {
URL u = new URL("jar:file:"/path/to/file.jar"!/");
URLClassLoader ucl = new URLClassLoader(new URL[] { u });
Driver d;
try {
d = (Driver)Class.forName("com.example.xxx.Driver", true, ucl).newInstance();
} catch (ClassNotFoundException e) {
logger.log(Level.ERROR, e.getMessage(), e);
}
DriverManager.registerDriver(new DriverDelegator(d));
} catch (Exception e) {
throw new AdapterException(e);
}
But in my case, How to load all classes of all jars in a directory and use for the "JDBC connection" driver with this method :
d = (Driver)Class.forName("com.example.xxx.Driver", true, ucl).newInstance();
How to implement it using URLClassLoader && Class.forName() ??
Thanks in advance,
~ Praz Solver