I have a database project which uses hibernate and is deployed as a snapshot to Nexus server. But I want to change url , username and password for test and production environment. Is there a way so that I can change properties of my hibernate.cfg.xml while maven build and then deploy it to nexus server and choose between two repositories to which I can deploy the artifact ?
like
<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<url>http://nexus:3344/nexus/content/repositories/snapshots</url>
</snapshotRepository>
<snapshotRepository>
<id>Project</id>
<url>http:/nexus:3344/nexus/content/repositories/Project</url>
</snapshotRepository>
</distributionManagement>
Hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://MyDatabase:3344/project</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hbm2ddl.auto">validate</property>
<property name="hibernate.c3p0.max_size">30</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.timeout">600</property>
<property name="hibernate.c3p0.aquire_increment">2</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<mapping class="com.jts1.db.dto.AddNewUserDTO" />
<mapping class="com.jts1.db.dto.AddProjectDBDTO" />
<mapping class="com.jts1.db.dto.AssignProjectsDTO"/>
<mapping class ="com.jts1.db.dto.IssueDBDTO"/>
<mapping class ="com.jts1.db.dto.AddCommentDTO"/>
</session-factory>
</hibernate-configuration>
Maven profiles and resource filtering should get you where you want to go:
For example:
pom.xml
hibernate.cfg.xml
This setup should allow you to do the following:
mvn clean deploy
,mvn clean deploy -Ptest
, ormvn clean deploy -Denvironment=test
should all deploy the test configuration to the test repository.mvn clean deploy -Pqa
, ormvn clean deploy -Denvironment=qa
should all deploy the QA configuration to the QA repository.