Different configuration file for dev and prod using Maven
Asked Answered
M

3

5

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

Marilee answered 25/8, 2011 at 10:44 Comment(0)
W
6

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.

Wampum answered 25/8, 2011 at 18:54 Comment(0)
C
2

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).

Chastity answered 25/8, 2011 at 10:49 Comment(0)
U
2

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.

Unwholesome answered 25/8, 2011 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.