I have Date base project as snapshot in nexus server which is using as dependency in my two web projects(test and production). but I am using two different databases for those two web projects. I want to use test data base for test web project and production data base for production web project. So I want to change hibernate configuration file path based on web project when the project is building in jenkins. My code snippet like this.
DBUtil.java
public class DBUtils {
private static SessionFactory sessionFactory;
private DBUtils() {
}
static {
Configuration configuration = new Configuration();
configuration.configure("/hibenateconfigpath");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
pom.xml
<repositories>
<repository>
<id>snapshots</id>
<name>Snapshots</name>
<url>url/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.my</groupId>
<artifactId>DBAccess</artifactId>
<version>0.0002-SNAPSHOT</version>
</dependency>
Please provide any solution to this with maven profiles or what ever it is.
You can use maven profiles to build your project. You have to define the profiles in your pom.xml:
In hibernate.cfg.xml file you can use the defined properties like this:
Then, you have to configure your build section in pom.xml:
Then you can call mvn clean install -Pdev|prod. You can also tell jenkins which profile you wish to build in the maven configuration.