To do so, there are some approaches (Configuration Server, System Properties, Configuration in Database). But what if you don't want to rely on external services/infrastructure? You want to keep the configuration inside your artifact but it has to be portable. Paradoxon? No. Solution?

So why don't you use templating? Because there's no such tooling? Now there is. In case you are using Maven you have a great base to start.

But let's see how to start. The most convenient way to handle configuration data is by using property files/resource bundles which are on your class path. You know at coding time, there is a specific file and you know how it's named. See this snippet here. It uses a resource named to read the value for jdbc.url

String getJdbcUrl() {
    Properties properties = new Properties();
    return properties.getProperty("jdbc.url");


This is very ok until you need to use a different configuration. This may be because of changed environments or a changed hostname of your database server. The big disadvantage is, that the content is static. So let's make it dynamic by using templates. Let's create a template with variables/placeholders:

[email protected]@

and a file/property source, which contains the correct values:


This file is somewhere outside of your code. You don't want to package it into your artifact. Imagine, you would do so and deploy the artifact then into your artifact repository, which is readable perhaps by the whole company: Everybody would gain access to your database passwords.

In the next step you would package the artifact and deploy it to the artifact repository. Still there is a template and a real config in it; The config points to some dev system, so we need something for post-processing the artifact. Let's use configurator-maven-plugin for it!

This plugin can perform artifact download and configuration in front of your application deployment. You define an artifact/file and define one or more property sources. Then you call the configuration goal.

mvn configurator:configure-artifact

After it's done, the configurator produces a post-processed/configured artifact which contains the right property values for your environment. You can drop that file into your application container. That's it. An example pom.xml snippet is:



You can find more documentation at Any issues with the plugin? Then go to

In the background the artifact file is extracted recursively (works for EAR's, WAR's, JAR's, WAR-in-EAR, JAR-in-EAR and so on). All files with the naming pattern *.template.* are scanned and processed, after processing the template-part in the file name is removed and the files are compressed again. Real post-processing for all kinds of configuration file templates: Properties, XML, JSON, ...