从tomcat访问classpath来动态编译代码片段
我有动态生成的 java 代码片段,它们引用 tomcat 类路径中具有公共 api 的类。我能够通过反射正确识别这些类的公共 api(方法),但是在使用这些信息生成我的 java 代码之后,我将使用 Java 编译器 API 来编译它。
这可能吗?我是否需要获取 tomcat 用于加载 servlet 的类路径并将其传递给 Java 编译器 API?
安迪
I have java code snippets dynamically generated which refer back to classes with public apis in the tomcat classpath. I am able to correctly identify the public apis (methods) of these classes thru reflection, but then after using this information to generate my java code I was to compile it with the Java Compiler API.
Is this possible? Do I need to get the classpath that tomcat has used to load my servlet somehow and pass it to the Java Compiler API?
Andy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须传递类路径..此代码会在类路径中检索内容
您将选项传递给compiler.getTask
CompilationTask任务=compiler.getTask(writer,memoryManager,diagnostics,options,classes,compilationUnits );
You will have to pass the classpath.. This code does the classpath retrieve stuff
You pass the options to the compiler.getTask
CompilationTask task = compiler.getTask(writer, memoryManager, diagnostics, options, classes, compilationUnits);