Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven, xml files for different profiles

Tags:

maven

profiles

I have maven pom with 2 profiles: dev and production

I have some xml files in my project. For example persistence.xml . Settings for dev and production environments are different

I need a way to have right files in dev and production assemblies

Maybe possible to have 2 copies of each xml file and put into assemblies right one? Or maybe possible to use settings from pom file inside xml file ?

Any other ideas or best practices?

like image 745
Victor Mezrin Avatar asked Dec 01 '12 09:12

Victor Mezrin


1 Answers

What you are looking for was already answered here: Maven: include resource file based on profile

Instead of having two files, another solution would be to use properties directly inside the properties.xml:

    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
    <property name="hibernate.connection.username" value="${db.username}"/>
    <property name="hibernate.connection.password" value="${db.password}"/>
    <property name="hibernate.connection.url" value="${db.connectionURL}/database"/>

In your pom.xml, define a value for each property for each environment:

<profile>
  <id>development</id>
  <properties>
    <db.username>dev</db.username>
    <db.password>dev_password</db.password>
    <db.connectionURL>http://dev:3306/</db.connectionURL>
  </properties>
</profile>
<profile>
  <id>production</id>
  <properties>
    <db.username>prod</db.username>
    <db.password>prod_password</db.password>
    <db.connectionURL>http://prod:3306/</db.connectionURL>
  </properties>
</profile>

You could then use filtering to enable token replacement by the right value in each environement:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

For mode details on this solution look at this page.

If you really need to have two copy of the same file, you could also use the

like image 77
Olivier.Roger Avatar answered Sep 18 '22 23:09

Olivier.Roger