日期:2014-05-20 浏览次数:20716 次
public class Test { public static void main(String[] args) { // 此时三个ClassLoader是同一个对象 System.out.println(Thread.currentThread().getContextClassLoader()); // 当前线程的类加载器 System.out.println(Test.class.getClassLoader()); // 当前类的类加载器 System.out.println(ClassLoader.getSystemClassLoader()); // 系统初始的类加载器 } }
------解决方案--------------------
final ClassLoader parent = findParentClassLoader(); String libDirString = System.getProperty("openfire.lib.dir"); File libDir; if (libDirString != null) { // If the lib directory property has been specified and it actually // exists use it, else use the default libDir = new File(libDirString); if (!libDir.exists()) { Log.warn("Lib directory " + libDirString + " does not exist. Using default " + DEFAULT_LIB_DIR); libDir = new File(DEFAULT_LIB_DIR); } } else { libDir = new File(DEFAULT_LIB_DIR); } // Unpack any pack files. unpackArchives(libDir, true); String adminLibDirString = System.getProperty("openfireHome"); if (adminLibDirString == null) { adminLibDirString = DEFAULT_ADMIN_LIB_DIR; } else { adminLibDirString = adminLibDirString+"/plugins/admin/webapp/WEB-INF/lib"; } File adminLibDir = new File(adminLibDirString); if (adminLibDir.exists()) { unpackArchives(adminLibDir, false); } else { Log.warn("Admin Lib Directory " + adminLibDirString + " does not exist. Web admin console may not work."); } ClassLoader loader = new JiveClassLoader(parent, libDir); Thread.currentThread().setContextClassLoader(loader); Class containerClass = loader.loadClass( "org.jivesoftware.openfire.XMPPServer"); containerClass.newInstance();