英文:
ClassNotFoundException for class in context.xml while jar is in lib folder of catalina home
问题
以下是您提供的内容的中文翻译部分:
我正在遵循此教程,使我的当前 Wicket 项目能够与 Redis 会话管理一起工作。
然而,我无法使我的 context.xml 起作用。
我正在从 2 个文件 CatalinaRedisSessionStore 和 RedisCache 制作一个 JAR 文件,然后将该 JAR 文件放入 tomcat 的 lib 文件夹中。
在启动我的应用程序后,我得到了这个错误:
SEVERE [main] org.apache.tomcat.util.digester.Digester.startElement Begin event threw exception
java.lang.ClassNotFoundException: com.company.web.wicket.redis.CatalinaRedisSessionStore
我的 context.xml 如下所示:
<?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>
我正在使用 azul/zulu-openjdk-alpine:11
在 Docker 容器中运行我的应用程序。
当我检查我的 Docker 容器时,JAR 文件位于 tomcat 主目录的 lib 文件夹中,所以根据文档,这应该足以使 tomcat 找到这个类。下面是我的 Dockerfile。
Dockerfile
# Pull base image.
FROM azul/zulu-openjdk-alpine:11
RUN apk update && apk add bash
# 设置时区为"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
执行了 jar xf redis_session.jar
后,文件夹结构如下所示:
英文:
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:
答案1
得分: 1
以下是翻译好的内容:
我假设您将 Application*.zip 文件复制到 Docker 镜像中,其中包含了 Tomcat 的安装。
按照以下方式更改您的 Dockerfile,应该可以解决问题:
FROM azul/zulu-openjdk-alpine:11
RUN apk update && apk add bash
# 将时区设置为 "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/
# 设置 CATALINA_HOME 并更新 PATH 环境变量是至关重要的,
# 因为您使用的是非官方的 Tomcat 基础镜像
ENV CATALINA_HOME /usr/local/tomcat
ENV PATH ${CATALINA_HOME}/bin:${PATH}
# Tomcat 的默认路径是 /usr/local/tomcat
# 所以,最好将应用程序解压到该文件夹,而不是自定义文件夹,
# 以避免 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
# 定义默认命令。
# 我们在开头定义的 $PATH 环境变量可以全局访问 /usr/local/tomcat/bin 中的所有内容。
# 因此,我们可以在全局范围内访问它们,而无需指定确切的脚本路径
CMD ["dockerstart.sh", "run"]
HEALTHCHECK --interval=1m --timeout=10s --retries=3 --start-period=2m CMD ${CATALINA_HOME}/bin/docker-healthcheck.sh
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论