我在IBM Rational Rhapsody的插件类中使用Guava库中的Optional类。
当我从Rhapsody中将该类作为插件运行时,对Optional类的调用会导致" java.lang.NoClassDefFoundError"错误,虽然当我在我的类main方法中调用它并将我的类作为Java应用程序运行时,它工作正常。 这是代码:
package com.example;
import com.google.common.base.Optional;
import com.telelogic.rhapsody.core.IRPApplication;
import com.telelogic.rhapsody.core.RPUserPlugin;
import com.telelogic.rhapsody.core.RhapsodyAppServer;
public class Test extends RPUserPlugin{
public static void main(String[] args) {
IRPApplication rhp = RhapsodyAppServer.getActiveRhapsodyApplication();
Optional<IRPApplication> app = Optional.of(rhp);
doSomething(app);
}
/**
* this is called by rhapsody
*/
@Override
public void RhpPluginInit(IRPApplication rpyApplication) {
IRPApplication rhp = RhapsodyAppServer.getActiveRhapsodyApplication();
Optional<IRPApplication> app = Optional.of(rhp);
doSomething(app);
}
}
答案 0 :(得分:0)
听起来像是一个类路径问题。确保将Google代码捆绑到插件jar中或在.hep文件中创建类路径条目。我使用Scala作为我选择的语言,并在所有地方使用选项,但我确保将scala运行时捆绑到我的插件jar文件中。此外,请确保在该接口中实现其余方法。作为插件,插件的REAL动作不会发生,直到Rhapsody通过Rhapsody中的“工具”菜单启动它时调用RhpPluginInvokeItem()方法。请参阅下面的示例:
public class Test extends RPUserPlugin{
IRPApplication rhp=null;
public static void main(String[] args) {
// no optionals in my example...
Test plugin = new Test();
IRPApplication app = RhapsodyAppServer.getActiveRhapsodyApplication();
if (app != null) {
plugin.RhpPluginInit(app);
plugin.RhpPluginInvokeItem();
} else System.out.println("No running Rhapsody application found.");
}
@Override
public void RhpPluginInit(IRPApplication rpyApplication) {
// Don't re-acquire the handle to the active application here, that gets
// handed to you in the parameter above (rpyApplication)
//IRPApplication rhp = RhapsodyAppServer.getActiveRhapsodyApplication();
rhp = rpyApplication;
// setup logic here...in preparation for RhpPluginInvokeItem() to be called.
}
@Override
public void RhpPluginInvokeItem() {
rhp.writeToOutputWindow("plugin","Invoking doSomething()...");
//doSomething();
}
// implement the rest of the overriden methods here...
}