Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different configuration file for dev and prod using Maven

I have to different log4j.xml and property files which are to be used in Dev and Production. I am using maven for building and packaging. Is there a way I can let maven choose dev or prod by a configurable maven property in POM or passing a run time variable?

Thanks, Abi

like image 267
Abhishek Avatar asked Aug 25 '11 10:08

Abhishek


3 Answers

The idea based on profiles in Maven is not the best, cause that would force you to run your build a couple of times which means if you have two environments you have to run your build twice if you have more just think about this. The best solution is to work with the Maven-Assembly-Plugin to create a set of artifacts for the different environments in a single step which will be distinct by the classifier. I have made a complete example here.

like image 69
khmarbaise Avatar answered Oct 28 '22 10:10

khmarbaise


Yes, use Maven profiles.

Profiles are specified using a subset of the elements available in the POM itself (plus one extra section), and are triggered in any of a variety of ways. They modify the POM at build time, and are meant to be used in complementary sets to give equivalent-but-different parameters for a set of target environments (providing, for example, the path of the appserver root in the development, testing, and production environments).

like image 29
Péter Török Avatar answered Oct 28 '22 09:10

Péter Török


As an alternative to profiles, which allows you to choose either "dev" or "prod" during your build, you might consider using the maven-assembly-plugin so that you can build both "dev" and "prod" assemblies every time you build.

like image 32
shelley Avatar answered Oct 28 '22 09:10

shelley