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

Java 在web应用程序中动态加载包含不在类路径中的其他类的依赖项的类,java,web-applications,classloader,Java,Web Applications,Classloader,我试图编译一个动态创建的类,该类具有其他类的依赖项,这些类是动态创建的。但我发现了一个例外 int errorCode = com.sun.tools.javac.Main.compile(new String[] { "-classpath", "bin", "-cp", ".;"+PATHCONST.TOOLS + ";" + PATHCONST.QUARTZ + ";" + PATHCONST.JUNIT + ";" +

我试图编译一个动态创建的类,该类具有其他类的依赖项,这些类是动态创建的。但我发现了一个例外

 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());

int errorCode=com.sun.tools.javac.Main.compile(新字符串[]{“-classpath”,“bin”,“-cp”,
“;”+PATHCONST.TOOLS+”;“+PATHCONST.QUARTZ+”;“+PATHCONST.JUNIT+”;“+
+System.getProperty(“java.class.path”),
“-d”,pathcont.TOMCAT_CLASSES_PATH,className});
ClassLoader cload=newURLClassloader(新URL[]{new File(ClassFilePath).toURI().toURL()},
Thread.currentThread().getContextClassLoader());
System.out.println(“错误代码和cload:+errorcode+”+cload);
Class c=Class.forName(文件名);
对象h=c.newInstance();
类c1=cload.loadClass(h.getClass().getName());

您能提供您编写的代码吗?谢谢,我发布了正确编译和加载的部分代码,但是如果我试图添加一个已经由该代码编译和加载的类,我会得到classnotfound errorint errorCode=com.sun.tools.javac.Main.compile(新字符串[]{“-classpath”,“bin”,“-cp”,“compile;”+PATHCONST.TOOLS+“;”+PATHCONST.QUARTZ+“;”+PATHCONST.JUNIT+“;”+h.getClass()+“;”+System.getProperty(“java.class.path”),“-d”,PATHCONST.TOMCAT_CLASSES_path,className});您可以看到他,getClass(),我正在添加到类路径中,但是@complilation会给出错误。我试着给出完整路径,你能提供你写的代码吗?谢谢,我发布了正确编译和加载的代码部分,但是如果我试图添加一个已经由该代码编译和加载的类,我会得到classnotfound errorint errorCode=com.sun.tools.javac.Main.compile(新字符串[]{“-classpath”,“bin”,“-cp”“,”;“+PATHCONST.TOOLS+”;“+PATHCONST.QUARTZ+”;“+PATHCONST.JUNIT+”;“+h.getClass()+”;“+System.getProperty”(“java.class.path”),“-d”,PATHCONST.TOMCAT_CLASSES_path,className});您可以看到他,getClass(),我正在添加到类路径中,但是@complilation会给出错误。我也试着给fullpath