Search code examples
dockermavenwebsphere-liberty

WebSphere liberty - shared libraries on docker image


I am using websphere-liberty(https://hub.docker.com/_/websphere-liberty/) image to deploy my apps but I have problems with shared libraries. I need to transform jar from util project into shared libraries on liberty server. Im stuck on this error:

SchedulerApplication- loaded ok - is from Scheduler app but it is extending class from util project

[ERROR   ] SRVE0276E: Error while initializing Servlet [Scheduler]: 

    javax.servlet.UnavailableException: SRVE0203E: Servlet [Scheduler]: com.scheduler.SchedulerApplication was found, but is missing another required class.
    SRVE0206E: This error typically implies that the servlet was originally compiled with classes which cannot be located by the server.
    SRVE0187E: Check your class path to ensure that all classes required by the servlet are present.SRVE0210I: This problem can be debugged by recompiling the servlet using only the classes in the application's runtime class path
    SRVE0234I: Application class path=[com.ibm.ws.classloading.internal.ThreadContextClassLoader@3c27eabb]
            at com.ibm.ws.webcontainer.servlet.ServletWrapper$1.run(ServletWrapper.java:1575)
            at [internal classes]

Basic project structure
    app - Scheduler/...
                /pom.xml
        - myapp2/...
                /pom.xml
        - util/...
              /pom.xml
        - pom.xml
    Dockerfile
    server.xml

Dockerfile

FROM maven:3.8.4-ibmjava-8 as maven_build
COPY --chown=1001:0 app./app
WORKDIR app
RUN mvn clean install

FROM websphere-liberty:21.0.0.12-full-java8-ibmjava
COPY --chown=1001:0  server.xml /config/
COPY --chown=1001:0 --from=maven_build /app/Scheduler/target/Scheduler.ear /config/dropins/ 
COPY --chown=1001:0 --from=maven_build /app/myapp2/target/myapp2.ear /config/dropins/

#util -> libraries used in both Scheduler & myapp2
COPY --chown=1001:0 --from=maven_build /app/util/target/util.jar /opt/ibm/wlp/usr/servers/defaultServer/lib/
RUN configure.sh

server.xml

.....
<library id="SharedLibraries" apiTypeVisibility="spec, ibm-api, stable, third-party">
    <fileset dir="/opt/ibm/wlp/usr/servers/defaultServer/lib/" includes="*.jar" scanInterval="5s" />
</library>

<application id="Scheduler" name="Scheduler" type="ear" location="Scheduler.ear">
      <classloader apiTypeVisibility="spec, ibm-api, stable, third-party" commonLibraryRef="SharedLibraries" />   
</application>
.....

Solution

  • Fixed after moving ear file out of config/dropins => stopped auto deploying

    Looks like app was installed 2x -auto deploy from config/dropins & deploy from server.xml

    COPY --chown=1001:0 --from=maven_build /app/Scheduler/target/Scheduler.ear /opt/ibm/wlp/usr/servers/defaultServer/apps