Java编译器api错误
我正在尝试在内存中编译一个实现接口的类。
我有一个名为 CacheRule 的接口(在 com/vpfw/proxy/logicRules/CacheRule.class 中)。
我有一个名为 CacheRuleBean 的类,我在内存中编译它。 如果此类未实现 CacheRule,则编译可以正常工作。但如果此类实现 CacheRule,则错误为:
java.lang.NoClassDefFoundError: com/vpfw/proxy/logicRules/CacheRule (wrong name: com/vpfw/proxy/logicRules/CacheRuleBean)
奇怪的是,如果我在 Eclipse 内执行此编译,则可以工作。 但是当我从 Tomcat 执行它时,我收到了之前的错误。
这是 CacheRule
接口的代码:
package com.vpfw.proxy.logicRules;
public interface CacheRule
{
void executeRule();
}
这是 CacheRuleBean
的代码:
package com.vpfw.proxy.logicRules;
import com.vpfw.proxy.logicRules.CacheRule;
public class CacheRuleBean implements CacheRule
{
public void executeRule() {}
}
编译调用是:
String[] compilationOptions = { "-cp", classDir };
return (new CompilerService().compile("com.vpfw.proxy.logicRules.CacheRuleBean",
source, compilationOptions));
其中
classDir
是目录 < code>/home/app/WEB-INF/classes 包含该项目的 com 文件夹(classPath 是正确的,如果我在中添加该项目的另一个类作为导入CacheRuleBean
,编译 好的)。- 我使用的类的名称是
com.vpfw.proxy.logicRules.CacheRuleBean
。 source
是CacheRuleBean
的源代码。- CompilerService 是我对编译器 API 的实现,它可以与除实现接口的类之外的所有类完美配合。
我可能做错了什么?
I'm trying to compile in-memory a class that implements an interface.
I have an interface named CacheRule (in com/vpfw/proxy/logicRules/CacheRule.class).
I have a class named CacheRuleBean
that I compile in-memory.
If this class does not implement CacheRule
, compilations works. But if this class implements CacheRule
, then the error is:
java.lang.NoClassDefFoundError: com/vpfw/proxy/logicRules/CacheRule (wrong name: com/vpfw/proxy/logicRules/CacheRuleBean)
Curiously, if I perform this compilation inside Eclipse, works.
But when I execute it from Tomcat, I get the previous error.
This is the code for the CacheRule
interface:
package com.vpfw.proxy.logicRules;
public interface CacheRule
{
void executeRule();
}
This is the code for CacheRuleBean
:
package com.vpfw.proxy.logicRules;
import com.vpfw.proxy.logicRules.CacheRule;
public class CacheRuleBean implements CacheRule
{
public void executeRule() {}
}
And the call to compile is:
String[] compilationOptions = { "-cp", classDir };
return (new CompilerService().compile("com.vpfw.proxy.logicRules.CacheRuleBean",
source, compilationOptions));
Where
classDir
is the directory/home/app/WEB-INF/classes
that contains thecom
folder of this project (classPath is correct, If I add another classes of this project as imports inCacheRuleBean
, compile ok).- The name of the class I use is
com.vpfw.proxy.logicRules.CacheRuleBean
. source
is the source code ofCacheRuleBean
.CompilerService
is my implementation of compiler API, which works perfectly with all classes except those that implement an interface.
What can I be doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论