Compile and install your OSGi plugin as an OSGi bundle

To use your OSGi plugin with PolicyCenter, you compile the plugin and then use Studio to register the plugin.

Before you begin

Create an OSGi-compliant Java class in a project in IntelliJ with OSGi Editor. Either perform the steps in Create an OSGi-compliant class that implements a plugin interface or use a class from the Java examples in the java-examples.zip file, which is located in the PolicyCenter installation directory.

Procedure

  1. If IntelliJ with OSGi Editor is not open, type the following command at a command prompt in the PolicyCenter root directory.
    gwb pluginStudio
  2. Open the OSGi Ant build script:
    1. Click View > Tool Windows > Ant.
      The Ant pane opens in IntelliJ with OSGi Editor.
    2. If OSGi plugin bundle is not open in the Ant pane, click the plus sign (+) in the navigation bar on that pane. In Select Ant Build File, navigate to and select build.xml in the project folder. Then, click OK.
      OSGi plugin bundle opens.
  3. Run the Ant install command:
    1. Expand OSGi plugin bundle.
    2. Right-click install and click Run Target.
    3. To see the result of running the command, click View > Tool Windows > Messages. Expand the targets to see the messages from each step.
    The command generates messages about compiling source files, generating files, copying files, building a JAR file, and finally copying that JAR file to the bundle deployment folder of PolicyCenter. If the command succeeds, the following output appears.
    Ant build completed successfully

    If the build completes with warnings, check the warnings and correct them if necessary.

  4. Switch to, or open, Guidewire Studio, not the IntelliJ IDEA with OSGi Editor. Navigate in the Project pane to the path configuration > deploy > bundles. Confirm that you see the newly-deployed file YOUR_JAR_NAME.jar.

    The JAR file name is based on the module symbolic name followed by the version. If the JAR file is not present at that location, check the Ant console output for the directory path where the script copied the JAR file. If you recently installed a new version of PolicyCenter at a different path, or moved your Guidewire product directory, you must immediately update your OSGi settings in your OSGi project.

  5. In Guidewire Studio, register your OSGi plugin implementation.
    Registering a plugin implementation defines where to find a plugin implementation class and what interface the class implements.
    1. In the Project window, navigate to configuration > config > Plugins > registry.
    2. Right-click the registry, and choose New > Plugin.
    3. In the plugin dialog, enter the plugin name in the Name field.

      For plugin interfaces that support only one implementation, enter the interface name without the package. For example: IBaseURLBuilder. The text that you enter becomes the basis for the file name that ends in .gwp. The .gwp file represents one item in the Plugins registry.

      If the plugin interface supports multiple implementations, like messaging plugins or startable plugins, this name can be any name of your choice.

      If you are registering a messaging plugin, the plugin name must match the plugin name in fields in the separate Messaging editor in Studio.

      For this demonstration implementation of the IStartablePlugin interface, enter the plugin name DemoStartablePlugin.

    4. In the plugin dialog, next to the Interface field, click the ellipsis (...), find the interface class, and select it. If you want to type the name, enter the interface name without the package.

      For this demonstration implementation of the IStartablePlugin interface, find or type the interface name IStartablePlugin.

    5. Click OK.
    6. In the Plugins registry main pane for the new plugin, click the plus sign (+) and click Add OSGi Plugin.
    7. In the Service PID field, type the fully qualified Java class name for your OSGi implementation class.

      Note that this name is different from the bundle name or the bundle symbolic name. The ellipsis (...) button does not display a picker to find available OSGi classes, so you must type the class name in the field.

      For this demonstration implementation of the IStartablePlugin interface, type the fully-qualified class name mycompany.DemoStartablePlugin.

    8. Set any other fields that your plugin implementation needs, such as environment, server, or plugin parameters.
    9. Make whatever other changes you need to make in Guidewire Studio. For example, if your plugin is a messaging plugin, configure a new messaging destination. You might need to make other changes such as changes to your rule sets or other related Gosu code.
    10. Start the server.

      Click the Run or Debug menu items or buttons.

      Alternatively, run the QuickStart server from the command prompt. Open a command prompt in the root application directory and run the following command.
      • gwb runServer

Example

Example startable plugin in Java using OSGi shows an example startable plugin. If you used that example, closely read the console messages during server start-up. The example OSGi startable plugin prints messages during server start-up. These messages demonstrate that PolicyCenter successfully called your OSGi plugin implementation.

What to do next