Class ClassLoaderUtils

  • All Implemented Interfaces:
    java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class ClassLoaderUtils
    extends javax.servlet.http.HttpServlet
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static java.lang.ClassLoader createClassLoader​(java.util.List<java.lang.String> jars)
      Load JDBC driver class from jar files specified as value of "jdbc.jars" property name in configuration file Value "jdbc.jars" must contains comma-separated JARs file names or URLs
      static void registerJdbcDriver​(java.lang.String jdbcDriverClassName, java.util.List<java.lang.String> driverJars)
      Register JDBC driver DriverManager will refuse to use a driver not loaded by the system ClassLoader The workaround for this is to use a shim class that implements java.sql.Driver.
      • Methods inherited from class javax.servlet.http.HttpServlet

        doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
      • Methods inherited from class javax.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • createClassLoader

        static java.lang.ClassLoader createClassLoader​(java.util.List<java.lang.String> jars)
        Load JDBC driver class from jar files specified as value of "jdbc.jars" property name in configuration file Value "jdbc.jars" must contains comma-separated JARs file names or URLs
        Parameters:
        array - of JAR files
        Returns:
        custom URL ClassLoader based on specified JAR files
      • registerJdbcDriver

        public static void registerJdbcDriver​(java.lang.String jdbcDriverClassName,
                                              java.util.List<java.lang.String> driverJars)
                                       throws java.lang.InstantiationException,
                                              java.lang.IllegalAccessException,
                                              java.lang.IllegalArgumentException,
                                              java.lang.reflect.InvocationTargetException,
                                              java.lang.NoSuchMethodException,
                                              java.lang.SecurityException,
                                              java.sql.SQLException,
                                              java.lang.ClassNotFoundException
        Register JDBC driver DriverManager will refuse to use a driver not loaded by the system ClassLoader The workaround for this is to use a shim class that implements java.sql.Driver. This shim class will do nothing but call the methods of an instance of a JDBC driver that is loaded dynamically. This works because DriverShim is loaded by the system class loader, and DriverManager doesn't care that it invokes a class that wasn't.
        Parameters:
        jars - value of "jdbc.jars" property name in configuration file
        classLoader - custom URL ClassLoader
        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.IllegalArgumentException
        java.lang.reflect.InvocationTargetException
        java.lang.NoSuchMethodException
        java.lang.SecurityException
        java.sql.SQLException
        java.lang.ClassNotFoundException
        See Also:
        DriverShim