Maven profiles : filtering for hsqldb and MySQL

Many developers like to use a lightweight embedded database such as Hsqldb or Derby in their development environment. But usually the application is deployed using another database such as MySQL – or Oracle, DB2 etc. Maven profiles are a way to segregate resources for each environment and to switch easily between them.

The Spring Framework allows you to put environment specific settings in Java properties files. You can read them in to your application context with a single line. First for convenience add the p namespace to your config file.

The testdb.properties file can contain actual values for each key. Instead we are going to use placeholders that will be expanded by maven.

testdb.properties

Here is another properties file with actual values. Maven will filter each of the placeholders in testdb.propeties with the value for each matching key in this file. The maven profile in use triggers this.

hibernatejpa-mysql.properties

In your pom.xml you define your profiles. You set up environment specific dependencies within your profile. Then you can specify which resource folders are filtered, those that are not and what file contains the actual values.
Here is a profile for MySQL that enables the filtering.

Resources

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.