• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to deploy different hibernate config file for qa/prod via maven

 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am running mvn compile war:war command to copy my project's war to the target for my server.

Now, I use hibernate config file that has db connection properties and I want to do following,
1. When I run mvn compile war:war with some additional properties "-Dtarget.db=prod" it should pickup hibernate config file for prod and copy it as hibernate.cfg.xml and then do deploy that to my tomcat in prod

I am not sure how to do this. Can anybody help me?

I know how to use properties in the maven pom.xml but I can't figure out how to do the above.

Any help is greatly appreciated.

PS: I know I can do similar task in Ant build file via copy task where depending upon property I can copy hibernate.cfg.${propname} as hibernate.cfg.xml and achieve the above effect but I want to do it via maven.

Regards
Maulin
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there, you want to investigate Maven's "profile" concepts and the usage of the assembly plugin to achieve this. In short you specify which profile you're running maven for (e.g. PRD) and the assembly plugin helps you pick up the right files..
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Martijn. I am starting to look into it.

Regards
Maulin
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I could do it by using only Profiles.

First as suggested, I learned how profiles work in maven and then I found the following thread on stackoverflow.

http://stackoverflow.com/questions/512516/how-to-copy-from-one-file-to-another-in-maven

(I didn't have to use assembly plugin at all. I read about it but felt thats not going to help my use case before I found above thread that exactly addressed what I wanted)

Essentially all I had to do was -
1. Create dev and prod Profiles
2. Within the profile I had to put build->resources->resource->directory xml element hierarchy and specify appropriate dev and prod resource folders

Slowly I am starting to love Maven! So far its amazing.

Regards
Maulin
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done! The best way is always to figure yourself
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Maulin

Let me think if i have understood your requirement correctly.
You have hibernate.cfg.xml which has entries varying wrt to environment.
1. Mostly it will be DB Connectivity things
2. Some tags specific to environment.

Questions
1. Let us assume you pack the configurations in tar or jar and give to deployment team.
Will you repack the jar for every environment or is it one time packing and
environment team keeps deploying in different environment.
for ex
you pack configurations for QA environment.
Once testing completes, will you give a release for prod or will you use the qa environment TAR.GZ for production deployment.


Case 1
If same tar to be used across environment, and settings to be changed localised to that environment.

Solution1.
Step 1. Let us take hibernate.cfg.xml, it has

Now this value varies wrt to varies environment.

Step 2. Create a Project called projectResources
with this file as hibernate.cfg.xml.template
edit the file in such a way


Step 3.
Have a properties file
local_db_connection_string=jdbc:Oracle:thin:@x.x.x.x:x:SID
Note: This properties will be residing in every environment, carrying values wrt to that environment.
QA local.properties will be
local_db_connection_string=jdbc:Oracle:thin:@x.x.x.x:x:QASID
PRod local.properties will be
local_db_connection_string=jdbc:Oracle:thin:@x.x.x.x:x:PRODSID

Step 4.
Now while giving a release , we have to pack the template file instead of hibernate.cfg.xml, in this way
we have a release generic to all environment
Step 5.
Now we have to use small program using velocity to replace the macro with values actual before deploying.
Check velocity how to replace macro with values.
pS: Any information /help on this let me know
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't like to create multiple versions of a WAR myself. It's much easier to debug production problems if the code is identical on the test sytem.

Instead, I supply the server/platform-specific data externally. For databases, that means using the server's database connection pooling facilities to that I can selected whichever database server I want at the appserver-level. For other things such as slapping a nice big "TEST" banner on the webpages for test apps, I use JNDI, code resource definitions in the web.xml file and override them in the server's deployment description.

I do have some projects using profiles, but that's because the test machines are Linux and the production machines are IBM mainframes and I actually have to vary the JARs included, since WebSphere has certain features built into it that Tomcat doesn't. There's limits to what you can externally configure, after all.
 
My cellmate was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic