Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat context.xml and context.properties file

Tags:

java

maven

tomcat

I have tomcat's context.xml file with references to the context.properties file

<Context sessionCookiePath="/" path="/">
<Resource name="jdbc/dbwriter" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
          driverClassName="com.mysql.jdbc.Driver"
          type="javax.sql.DataSource"
          url="jdbc:mysql://${context.ip}:3306/test" username="${user}"
          password="${pass}" />
</Context>

The context.properties file looks like:

context.ip=localhost
user=admin
pass=admin

But it seems that tomcat does not load the properties file and tries to resolve jdbc:mysql://${context.ip}:3306. What am I doing wrong?

For build I am using maven. Maybe it should fill up the property placeholders?

EDIT: the context.properties file is located in side WEB-INF/classes folder, and context.xml is located in the META-INF folder inside the WAR file.

like image 913
Dagaz Avatar asked Dec 07 '25 23:12

Dagaz


1 Answers

There is little point shipping your context.properties file as part of the web application. You might as well have the build system do the property replacement for you.

If you want to keep the property definitions, Tomcat will pick up those properties if you add them to the catalina.properties file located in $CATALINA_BASE/conf

like image 77
Mark Thomas Avatar answered Dec 09 '25 11:12

Mark Thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!