简体   繁体   中英

ClassNotFoundException for class in context.xml while jar is in lib folder of catalina home

I am following this tuturial to make my current wicket project work with Redis Session management. However, I can't make my context.xml work. I am making a JAR from 2 files, CatalinaRedisSessionStore and RedisCache, then I am putting that jar in the lib folder of tomcat.

After starting my application I am getting this error:

SEVERE [main] org.apache.tomcat.util.digester.Digester.startElement Begin event threw exception
    java.lang.ClassNotFoundException: com.company.web.wicket.redis.CatalinaRedisSessionStore

My context.xml looks like this:

<?xml version="1.0" ?>
<Context>
    <Manager className="org.apache.catalina.session.PersistentManager"
             maxIdleBackup="1"
             minIdleSwap="0"
             maxIdleSwap="0"
             processExpiresFrequency="1"
             saveOnRestart='true'>
        <Store className="com.company.web.wicket.redis.CatalinaRedisSessionStore"/>
    </Manager>
</Context>

I am running my application in a docker container, using azul/zulu-openjdk-alpine:11

When I inspect my docker container, the jar file is in the lib folder of the tomcat home, so according to the docs that should be sufficient for tomcat to find the class. Below I have put my Dockerfile.

Does anyone have any clue why the class cannot be found?

Dockerfile

FROM azul/zulu-openjdk-alpine:11


RUN apk update && apk add bash

#set timezone to "Europe/Amsterdam"
RUN apk add tzdata && cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime && echo "Europe/Amsterdam" >  /etc/timezone && apk del tzdata

COPY /build/distributions/Application*.zip /opt/application/

RUN unzip /opt/application/Application*zip -d /opt/application && rm /opt/application/Application*.zip && chmod 775 /opt/application/apache-tomcat/bin/catalina.sh && chmod 775 /opt/application/apache-tomcat/bin/docker-healthcheck.sh

WORKDIR /opt/application/apache-tomcat

EXPOSE 8080 9875 9000

# Define default command.
CMD ["/opt/application/apache-tomcat/bin/dockerstart.sh","arg1"]

HEALTHCHECK --interval=1m --timeout=10s --retries=3 --start-period=2m CMD /opt/application/apache-tomcat/bin/docker-healthcheck.sh

After executing jar xf redis_session.jar, folder structure as follows: jar文件结构

I assume that the Application*.zip file you copy into the Docker image contains the Tomcat installation.

Changing your Dockerfile as follows should solve the problem:

FROM azul/zulu-openjdk-alpine:11

RUN apk update && apk add bash

#set timezone to "Europe/Amsterdam"
RUN apk add tzdata && \
    cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime && \
    echo "Europe/Amsterdam" >  /etc/timezone && \
    apk del tzdata

COPY /build/distributions/Application*.zip /tmp/

# Setting CATALINA_HOME and updating the PATH env vars is crucial
# since you use an inofficial Tomcat base image
ENV CATALINA_HOME /usr/local/tomcat
ENV PATH ${CATALINA_HOME}/bin:${PATH}

# The default path of Tomcat is /usr/local/tomcat
# So, it's a good idea to extract your application to that folder
# rather than to a custom one to avoid an unexpected behaviour of the Tomcat
RUN unzip  /tmp/Application*.zip -d /usr/local && \
    rm /tmp/Application*.zip && \
    mv /usr/local/apache-tomcat ${CATALINA_HOME} && \
    chmod 775 ${CATALINA_HOME}/bin/catalina.sh && \
    chmod 775 ${CATALINA_HOME}/bin/dockerstart.sh && \
    chmod 775 ${CATALINA_HOME}/bin/docker-healthcheck.sh

WORKDIR ${CATALINA_HOME}

EXPOSE 8080 9875 9000

# Define default command.
# Everything inside /usr/local/tomcat/bin is exposed through the $PATH env var we defined at the beginning. 
# So we can access them globally without having to specify the exact script path
CMD ["dockerstart.sh", "run"]

HEALTHCHECK --interval=1m --timeout=10s --retries=3 --start-period=2m CMD ${CATALINA_HOME}/bin/docker-healthcheck.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM