maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adeelmahmood <adeelmahm...@gmail.com>
Subject maven profiles - load config.properties based on environment
Date Thu, 28 Mar 2013 14:54:50 GMT
I am trying to setup maven profiles in a way that allows me to read a
properties file based on an environment property e.g. either
config-dev.properties or config-prod.properties and then have those
propreties within the config-*.properties files available for the
application to use. I am kind of new to the maven profiles concept so I am
not sure what the best way is to set something up like this. This is how I
have things setup so far (following
http://www.petrikainulainen.net/programming/maven/running-solr-with-maven/)

-- Pom.xml
<profiles>
              <profile>
                     <id>dev</id>
                     <activation>
                           <activeByDefault>true</activeByDefault>
                     </activation>
                     <properties>
                           <build.profile.id>dev</build.profile.id>
                     </properties>
              </profile>
              <profile>
                     <id>prod</id>
                     <activation>
                           <property>
                                  <name>WASENV</name>
                                  <value>PROD</value>
                           </property>
                     </activation>
                     <properties>
                           <build.profile.id>prod</build.profile.id>
                     </properties>
              </profile>
       </profiles>

                <build>
              <finalName>solr</finalName>

              <filters>
                    
<filter>${project.basedir}/src/main/resources/config-${build.profile.id}.properties</filter>
              </filters>
              <resources>
                     <resource>
                           <filtering>true</filtering>
                           <directory>src/main/resources</directory>
                     </resource>
              </resources>

                                ……

                                <plugin>
                           <groupId>org.mortbay.jetty</groupId>
                           <artifactId>jetty-maven-plugin</artifactId>
                           <version>8.1.8.v20121106</version>
                           <configuration>
                                  
                                 
<systemPropertiesFile>${project.basedir}/src/main/resources/config-${build.profile.id}.properties</systemPropertiesFile>
                                  <stopPort>9966</stopPort>
                                  <stopKey>stop</stopKey>
                                  <connectors>
                                         
                                         <connector
implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                                                <port>8983</port>
                                               
<maxIdleTime>60000</maxIdleTime>
                                         </connector>
                                  </connectors>
                                  <webApp>
                                         <contextPath>/solr</contextPath>
                                  </webApp>
                           </configuration>
                     </plugin>
              </plugins>
       </build>

So first thing I have defined two profiles (dev and prod). Dev is active by
default and prod is activated based on WASENV environment variable/system
property/jndi entry (I am hoping). Then in the build section I am using
maven filtering to read the correct config.properties based on the activated
profile id. Also in the jetty configuration I am reading system properties
from the config.properties based on activated profile id. This works fine if
I run the app with jetty. If I run with jetty:run –P dev or –P prod, it
loads the correct profile and the correct config.properties file and
everything works.

However when I package it into a war file and deploy on tomcat, nothing
really happens (neither config.properties file is loaded). The fact is I am
not even sure how its supposed to work because maven is a build tool so if
the war is already built how can any of this activation of correct profile
will happen in tomcat based on environment variable. This is where I think I
am not sure how deployment based on profiles is supposed to work and can use
some help in understanding this better.

Any help would be appreciated.

Thanks
Adeel




--
View this message in context: http://maven.40175.n5.nabble.com/maven-profiles-load-config-properties-based-on-environment-tp5752105.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Mime
View raw message