How to share database properties in Maven 3 multi modules projects?

Tag: maven Author: kelly23625 Date: 2010-10-12

Let's assume there are 2 applications. The POM hierarchy might look like this:

   --> system A
   --> system B

Both systems are supposed to be able to connect to the same database.

Each system has 2 profiles: Development (embedded DB) and Production (MySQL).

How can I use Maven to share the database connection information (user, path, driver etc.) for each profile ACROSS BOTH systems (I'm using resource filtering)?

Best Answer

Just store the properties for those information in the appropriate profile.


do you mean in each system individually (redundancy?) or in the parent pom (I thought profiles don't inherit) ?
Define the profile in the root pom and the set properties will be used in the derived project (of course only if you using a multimodule build).
just tried it: it works :) thx!
argh - pressed the wrong arrow - then SO said it's in "maintanance" and now I can't change the vote "unless the answer is edited"
Just edited (just added newline). Just try to change it.

Other Answer1

Take care when deciding where database connection information will be stored. While it's ok to store driver and url in pom.xml (so this info probably goes to source repository and can be accessed by anyone who is granted access to the source), username and password should not be exposed usually. So they are better specified in settings.xml. This is especially important in your case, when you work with production database. Nice explanation can be found here