hi arash,
as far as i am aware (i've only been using maven for about 6 months so
i'm no real authority on it) but the easiest way to accomplish is to
have the properties defined in the environment profiles, eg in your main
pom:
<profile>
<id>build</id>
<activation>
<property>
<name>env</name>
<value>build</value>
</property>
</activation>
<properties>
...
</properties>
</profile>
Unfortunately i don't think it's possible to activate other profiles
within this profile, so you couldn't have a generic environment profile
which was activated by all other specific env profiles. What you can do
however is 'override' this parent profile in module poms. This allows
for a module to add env config into the same profile which can all be
activated using the same command line parameter. I found this good in
keeping module config in the module pom.
Reading
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
section "Profile Pitfalls", Maven promotes that env config should reside
in the pom so that the project can always be built without relying on
external property configuration. I've found this to be fine for
everything but the env passwords which should be the only thing required
to be configured outside the project in the build's settings.xml file, eg:
<profile>
<id>build</id>
<activation>
<property>
<name>env</name>
<value>build</value>
</property>
</activation>
<properties>
<database.password>AbCdEfG</database.password>
</properties>
</profile>
This has worked for me with local, dev, build, staging and prod
environments. At first i found defining properties for each environment
seperatly a bit of overhead but it does pay off with the simplicity and
inherant flexibility of being able to change any property for a specific
environment independently. The other great benefit is being able to
change the build in this profile, so for example the build profile can
automatically create the user and database during the build - something
you might not want happening for prod.
Cam
Arash Bizhan zadeh wrote:
Hi all,
I know it is a well known issue but I am really stuck!
I am in the process of migrating some Java applications build system to
Maven 2. developers need to build the applications for different environment
like local/staging/QA/prod. in the old build system we have one property
file including all the environment related properties and we used to pass it
to build and get the job done.
These parameters includes actual values for filtered variables as well as
paths and plug in properties (ie. webapps.root for cargo plugin)
I created different profiles for different environment and everything was
going on well until I noticed that I can not load the property files inside
maven. Each profile needs to load one of the environment specific property
files; so that the rest of the maven could use it.
could somebody shed a light on this problem and guide me to load my property
file in maven, or tell me about any other solution.
regards,
Arash
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]