How can I set a delegation parentLast when using open liberty-maven-plugin?

136 views Asked by At

I have two applications that need to set the classloader as delegation="parentLast".

On one hand, I have an app that I don't need to develop over them (called sites.ear), I just used it as it is, so I don't need to integrate this EAR in my IDE. Because of this, I configure this app on my server.xml directly.

On the other hand, I have an app called "blog" that I am working on. If I set the lines below in my server.xml, it works fine, but If I do that, I can't not work using the liberty-maven-plugin (starting the app from the IDE). If I try to start the app using IntelliJ, then it deploy the code twice, one from the server.xml and another one by the plugin (mvn liberty:run)

    <application id="app-blog" location="C:\Code\app-blog\target\app-blog.ear" name="wem-app-blog" type="ear">
        <classloader commonLibraryRef="global" delegation="parentLast"></classloader>
    </application>    

This is my pom.xml that I have configured in my app-blog

<plugin>
  <groupId>io.openliberty.tools</groupId>
  <artifactId>liberty-maven-plugin</artifactId>
  <version>3.6</version>
  <configuration>
    <installDirectory>C:\wlp-webProfile8-21.0.0.12\wlp</installDirectory>
    <jvmOptionsFile>C:\wlp-webProfile8-21.0.0.12\wlp\usr\servers\defaultServer\jvm.arguments.txt</jvmOptionsFile>
  </configuration>
</plugin>

this is my server.xml

<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">

    <library id="global">
        <fileset dir="C:\sdk\libs-classpath" includes="*.jar"/>
    </library>

    <!-- Enable features -->
    <featureManager>
        <feature>webProfile-8.0</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443"/>

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>

    <application id="sites" location="C:\sdk\websphere\sites.ear" name="sites" type="ear">
        <classloader commonLibraryRef="global" delegation="parentLast"></classloader>
    </application>
    
    <!-- Default SSL configuration enables trust for default certificates from the Java runtime --> 
    <ssl id="defaultSSLConfig" trustDefaultCerts="true" />
</server>

I also tried to configure the classloader to parentLast in a global way, but it does not work.

Basically, I want to work with the open liberty server integrated to my IDE IntelliJ and I want to start and stop the server using the IDE. Right now, I am not able to start the from the IDE using the classloader parentLast.

Is there an way to work integrated with the IDE deploying the classloader to parentLast?

Any ideas or suggestions is appreciate.

Thank you

1

There are 1 answers

3
Scott Kurz On BEST ANSWER

SOLUTION:

Configure your application with a "location" matching simply the "basename" of your application archive, e.g.:

<application id="app-blog" location="app-blog.ear" name="wem-app-blog" type="ear">
  <classloader commonLibraryRef="global" delegation="parentLast"/>
</application>    

(NOTE: you might need to adjust this if you are deploying the artifact to include the version in the filename, either adding the version in the server.xml or using the "stripVersion" config parameter).

EXPLANATION

The Liberty Maven/Gradle plugins make an effort to auto-generate deployment configuration for an application deployed via the plugins, (either directly via the 'deploy' goal of liberty-maven-plugin or deployed as part of the 'run' or 'dev' goals).

However, this can cause problems if you need to provide your own non-default configuration (for something like parent-last classloading) if your configuration does not align with the configuration generated by the Liberty Maven/Gradle plugins. The plugin can end up treating your config as if it were config for a different app, and think it needs to go ahead and generate its own config, and now you have two configs for one app, and only one has the correct attributes, customizations, etc.

NOTE: I would also try this on the latest liberty-maven-plugin version (v3.9) since we've had some fixes in this area over the past years.