You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by moraleslos <mo...@hotmail.com> on 2007/02/12 23:17:37 UTC

profiles / text substitution

I would like to use maven profiles in the pom but would like someway to
combine this with text substitution.  Basically I would like to have one
generic hibernate configuration file that has a ${connection} ready for
runtime text substitution.  Then I would have 2 external files that contains
the appropriate connection properties, e.g. connection-dev.properties and
connection-prod.properties.  I would like to profile these directly in the
pom, and then invoke maven in the command line specifying the appropriate
profile.  So, for example, when I do this-- mvn -Denv=dev package-- I would
like maven to package my hibernate config file, substituting the
${connection} with that found in connection-dev.properties.  Is there a way
to do this with maven profiles?  Thanks in advance!

-los
-- 
View this message in context: http://www.nabble.com/profiles---text-substitution-tf3217012s177.html#a8934189
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


Re: [m2] profiles / text substitution

Posted by franz see <fr...@gmail.com>.
Good day to you, los,

Do something like this

<project>
  ...

  <build>
    <resources>
      <resource>
        <directory>src/main/config</directory>
        <includes>
          <include>hibernate.cfg.xml</include>
        </includes>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>

  <profiles>
    <profile>
      <id>dev</id>
      <activation>
        <property>
          <name>env</name>
          <value>dev</value>
        </property>
      </activation>
      <build>
        <filters>
          <filter>src/main/filters/connection-dev.properties</filter>
        </filters>
      </build>
    </profile>
    <profile>
      <id>prod</id>
      <activation>
        <property>
          <name>env</name>
          <value>prod</value>
        </property>
      </activation>
      <build>
        <filters>
          <filter>src/main/filters/connection-prod.properties</filter>
        </filters>
      </build>
    </profile>
  </profiles>

</project>

The filtering is done using filter files ( see [1] ), while the filter file
to be used depends on which profile is activated. You can user property
activation to specify which profile to use ( see [2] ).

This is assuming that your directory structure is something like this...

.
 `-- src
      `-- main
           |-- filters
           |    |-- connection-dev.properties
           |    `-- connection-prod.properties
           `-- config
                `-- hibernate.cfg.xml

Cheers,
Franz

[1]
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
[2] http://docs.codehaus.org/display/MAVENUSER/Profiles


moraleslos wrote:
> 
> I would like to use maven profiles in the pom but would like someway to
> combine this with text substitution.  Basically I would like to have one
> generic hibernate configuration file that has a ${connection} ready for
> runtime text substitution.  Then I would have 2 external files that
> contains the appropriate connection properties, e.g.
> connection-dev.properties and connection-prod.properties.  I would like to
> profile these directly in the pom, and then invoke maven in the command
> line specifying the appropriate profile.  So, for example, when I do
> this-- mvn -Denv=dev package-- I would like maven to package my hibernate
> config file, substituting the ${connection} with that found in
> connection-dev.properties.  Is there a way to do this with maven profiles? 
> Thanks in advance!
> 
> -los
> 

-- 
View this message in context: http://www.nabble.com/profiles---text-substitution-tf3217012s177.html#a8942185
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


Re: profiles / text substitution

Posted by Wayne Fay <wa...@gmail.com>.
You want to use profiles plus filters. This is certainly possible, and
in fact rather simple with Maven2.

Much more information on these topics is available in the Better
Builds With Maven free e-book from www.mergere.com.

Also this blog post should probably be helpful:
http://sujitpal.blogspot.com/2006/10/maven2-multi-environment-filter-setup.html

Wayne

On 2/12/07, moraleslos <mo...@hotmail.com> wrote:
>
> I would like to use maven profiles in the pom but would like someway to
> combine this with text substitution.  Basically I would like to have one
> generic hibernate configuration file that has a ${connection} ready for
> runtime text substitution.  Then I would have 2 external files that contains
> the appropriate connection properties, e.g. connection-dev.properties and
> connection-prod.properties.  I would like to profile these directly in the
> pom, and then invoke maven in the command line specifying the appropriate
> profile.  So, for example, when I do this-- mvn -Denv=dev package-- I would
> like maven to package my hibernate config file, substituting the
> ${connection} with that found in connection-dev.properties.  Is there a way
> to do this with maven profiles?  Thanks in advance!
>
> -los
> --
> View this message in context: http://www.nabble.com/profiles---text-substitution-tf3217012s177.html#a8934189
> 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
>
>

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