open-liberty

How to load dependencies in a Open Liberty Bell extension?


I have implemented a custom user registry for Open Liberty using the Bell feature.

I activate it using the following snippet:

<featureManager>
    <!-- To enable the custom user registry-->
    <feature>bells-1.0</feature>
    <!-- Required in the CUR -->
    <feature>jsonb-3.0</feature>
</featureManager>
<library id="bellsCurLib" name="bellsCurLib">
    <file name="${server.config.dir}/resources/ol-cur.jar"/>
</library>
<bell libraryRef="bellsCurLib" enableSpiVisibility="true">
    <properties
        prop1="value1"
        prop2="value2"/>
</bell>

In order to support Java 8, I had to switch from the Java HTTP Client to Apache HTTP Client. This introduces a number of required dependencies that need to be available when the user registry is created and initialized. I got it working by adding the dependencies into a "fat jar" aka uber-jar using the Maven assembly plugin. That's obviously not very elegant, and I'm wondering if there could be any side effects on applications using this Bell loaded custom user registry.

Now my question: How can I add these dependencies in a different, cleaner way?

Many thanks in advance for helping!


Solution

  • Your applications should suffer no side effects when using a custom user registry deployed as a bell. Since your UserRegistry service implementation is provided by a shared library, you should avoid referencing bellsCurLib within any <classloader/> configurations.

    The <bell/> configuration references a shared library, which includes all binaries and resources required by your UserRegistry service implementation except for Open Liberty API/SPI and java packages. I'm not aware of a "cleaner" way to assemble the required dependencies into a single library jar, but you needn't deploy a single library jar as this tutorial suggests. You can cache the dependencies to a reserved location in the server environment and configure the library to also include these dependencies.

    <variable name="oss.dependencies.dir" value="/some/root/path/containing/oss/jars/and/resources/" />
    
    <library id="bellsCurLib" name="bellsCurLib">
        <file name="${server.config.dir}/resources/ol-cur.jar" />
        <fileset dir="${oss.dependencies.dir}" include="file-name-pattern-1, file-name-pattern-2, ..." />
        <folder dir="${oss.dependencies.dir}/path/containing/resources/" /> 
    </library>
    

    FYI, your shared library referenced by the bell requires the UserRegistry interface, which is an Open Liberty API of type ibm-api. The server makes this API type available to libraries by default. So, your <library/> configuration is fine in this regard -- you needn't configure the apiTypeVisibility attribute of the <library/> to make the API available to the service implementation. SPI visibility for libraries referenced by a bell is a relatively new feature. Unless your service implementation also requires SPI, you needn't configure attribute spiVisibility="true" in the <bell/>. And that begs the question: Did you find a user document that mentions attribute enableSpiVisibility? If so, please post a reference as the document contains a typo. Thanks!