0

I am using the Optional class from Guava library in a plugin class for IBM Rational Rhapsody.

When I run the class as a plugin from inside Rhapsody, the call to the Optional class causes "java.lang.NoClassDefFoundError" error, although when I call it in my class main method and run my class as a java application it works fine. Here is the code:

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);
  }

}
Ahmed Waheed
  • 1,281
  • 5
  • 21
  • 39

1 Answers1

0

Sounds like a classpath problem. Make sure you either bundle the Google code into your plugin jar OR make a classpath entry in your .hep file. I use Scala as my language of choice and use options all over the place but I make sure to bundle the scala runtime into my plugin jar file. Also, be sure to implement the rest of the methods in that interface. As a plugin the REAL action of the plugin doesn't happen until Rhapsody invokes the RhpPluginInvokeItem() method when you initiate it via the Tools menu inside Rhapsody. See my example below:

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...
}
bauhaus9
  • 181
  • 1
  • 12