1

I have a war file that I deployed with Tomcat.
I have a Dockerfile and at the end I build a kubernetes pod.

The problem is that if my property files from my app do exist in the path: /usr/local/tomcat/webapps/myapp/WEB-INF/classes/config/ and not in path /usr/local/tomcat/webapps/myapp/WEB-INF/classes/, so the application does not start.

Is it possible to set a classpath in Tomcat to point to a specific folder?
For example, I want to set classpath like: /usr/local/tomcat/webapps/myapp/WEB-INF/classes/config/.
I don't want to have duplicate property files.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250

1 Answers1

1

As mentioned here:

foo.properties is supposed to be placed in one of the roots which are covered by the default classpath of a webapp, e.g. webapp's /WEB-INF/lib and /WEB-INF/classes, server's /lib, or JDK/JRE's /lib.

  • If the properties file is webapp-specific, best is to place it in /WEB-INF/classes.
  • If you're developing a standard WAR project in an IDE, drop it in src folder (the project's source folder).
  • If you're using a Maven project, drop it in /main/resources folder.

You can alternatively also put it somewhere outside the default classpath and add its path to the classpath of the appserver.
In for example Tomcat you can configure it as shared.loader property of Tomcat/conf/catalina.properties.

Example:

FROM tomcat:8.5-jre8
 
# $CATALINA_HOME is defined in tomcat image
ADD target/my-webapp*.war $CATALINA_HOME/webapps/my-webapp.war
 
# Application config
RUN mkdir $CATALINA_HOME/app_conf/
ADD src/main/config/test.properties $CATALINA_HOME/app_conf/
 
# Modify property 'shared.loader' in catalina.properties
RUN sed -i -e 's/^shared.loader=$/shared.loader="${catalina.base} \/ app_conf"/' $CATALINA_HOME/conf/catalina.properties
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I have only one problem, I also have log4j in the config folder and he doesn't see it. It must be overwritten with the values ​​from kubernetes, the values ​​are ok but still in the container logs I see errors related to the old log4j – Eugen Gîrlescu Jun 16 '22 at 08:04
  • @EugenGîrlescu OK, that could be addressed in a new question. – VonC Jun 16 '22 at 08:37