在Web应用程序中动态加载包含不在类路径中的其他类的依赖项的类

时间:2016-02-02 04:53:22

标签: java web-applications classloader

我正在尝试编译一个动态创建的类,该类具有动态创建的其他类的依赖项。但是我得到了classNotFound异常

 int errorCode = com.sun.tools.javac.Main.compile(new String[] { "-classpath", "bin", "-cp",
            ".;"+PATHCONST.TOOLS + ";" + PATHCONST.QUARTZ + ";" + PATHCONST.JUNIT + ";" + 
                    + System.getProperty("java.class.path"),
            "-d", PATHCONST.TOMCAT_CLASSES_PATH, className });  
    ClassLoader cload = new URLClassLoader(new URL[] { new File(ClassFilePath).toURI().toURL() },
            Thread.currentThread().getContextClassLoader()); 

    System.out.println("errorcode and cload : "+errorCode+" "+cload);

    Class c = Class.forName(fileN);
    Object h = c.newInstance();

    Class<?> c1 = cload.loadClass(h.getClass().getName());

0 个答案:

没有答案