Do what Stephan said. This is how I build all of my webapps.
I have 2 fundamental and virtually inviolable rules for my applications
1. It should be possible to build a production-ready unit without using an
IDE. Usually that means I use Maven, but sometimes Ant, Gradle, or whatever.
2. The
exact same byte-for-byte WAR/JAR/EAR should be installed in production as was used for development and testing.
To do that, I do as Stephan has outlined and put my environmental information in Tomcat's JNDI dictionary.
Note that in the case of database connections,
you should be using Tomcat database connection pool, so in that particular case, you should never have coded the connection URL, database user ID or password in the webapp at all. If you were placing pool meta-data or other configuration elements in a META-INF/context.xml file in the WAR, that's OK for development, but then you'd override that using the production server's Context element used to deploy the webapp.