开发者

Java compiler api error

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 the com folder of this project (classPath is correct, If I add another classes of this project as imports in CacheRuleBean, compile ok).
  • The name of the class I use is com.vpfw.proxy.logicRules.CacheRuleBean.
  • source is the s开发者_Go百科ource code of CacheRuleBean.
  • 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜