5
您好我有要求创建,编译和加载Java类运行时。使用FTL我创建java源文件,并且如果没有动态依赖关系,就能够编译源代码。使用Java编译器API来编译多个java文件
为了详细说明一个实例,我有两个java源文件,一个接口和它的实现类。我能够编译使用Java编译器API如下
String classpath=System.getProperty("java.class.path");
String testpath =classpath+";"+rootPath+"/lib/is_wls_client.jar;"+rootPath+"/rtds_wls_proxyclient.jar;.;";
File javaFile = new File(javaFileName+".java");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
List<String> optionList = new ArrayList<String>();
optionList.addAll(Arrays.asList("-classpath",testpath));
StandardJavaFileManager sjfm = compiler.getStandardFileManager(null, null, null);
Iterable fileObjects = sjfm.getJavaFileObjects(javaFile);
JavaCompiler.CompilationTask task = compiler.getTask(null, null, null,optionList,null,fileObjects);
task.call();
sjfm.close();
我设置静态类,其已经在classpath类路径的界面,但是这种方法不用于动态创建类的工作?任何自定义类加载器都可以修复?我的最终实施将是在网络/应用服务器
任何反馈将得到高度赞赏
Satheesh
定义一个类后,您需要解决它。 – 2015-12-17 16:14:25