Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JCL to load plugin.jar with driver inside #27

Open
drenda opened this issue Jul 26, 2014 · 0 comments
Open

JCL to load plugin.jar with driver inside #27

drenda opened this issue Jul 26, 2014 · 0 comments

Comments

@drenda
Copy link

drenda commented Jul 26, 2014

Hi,
I'm a server side Java app (run with maven jetty) and I need to load, when required, a plugin.jar that is outside the classpath.
I do this with this code:

JarClassLoader jcl = new JarClassLoader();
jcl.add(pluginFile.getPath());
JclObjectFactory factory = JclObjectFactory.getInstance();

            // Create object of loaded class

            JarFile jarFile = new JarFile(pluginFile);
            Enumeration<JarEntry> e = jarFile.entries();
            while (e.hasMoreElements()) {
                JarEntry je = (JarEntry) e.nextElement();
                if (je.isDirectory() || !je.getName().endsWith(".class")) {
                    continue;
                }
                // -6 because of .class
                String className = je.getName().substring(0, je.getName().length() - 6);
                className = className.replace('/', '.');
                Object obj = factory.create(jcl, className);
                log.debug("Classe restituita: "+obj);
                return obj;
            }

then I invoke a method from this plugin class, say doSomething().

My plugin class in short make an access to a datasource (Dmbs) and inside is is included the jar needed to access the db.

in my doSomething() method I do this:

JarClassLoader jcl = new JarClassLoader();
jcl.add(".");
JclObjectFactory factory = JclObjectFactory.getInstance();
// Create object of loaded class
Object obj = factory.create(jcl, "com.mysql.jdbc.Driver");
Class.forName(dataSet.getDriver(), true, jcl);

Unfortunally when my server app try ti invoke doSomething() method I've always this exception:

26/07/2014 10:17:01 ERROR PluginManager:70 -
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/db
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)

Jcl is supposed to solve this situation?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant