You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by MavenUser8979 <mi...@yahoo.com> on 2011/10/25 15:09:41 UTC

Replacing properties with Maven.

All,

I have one requirement where I want to read all the parameterized properties
from one file and replace it in other file.

e.g.

parameterized.properties is having below two properties.

LOG_DIR=/application/logs
INSTALL_DIR = /application/config

Now I have other property file project.properties with below two properties.

logDirectory=@LOG_DIR@
installDir=@INSTALL_DIR@

After I replace strings from "parameterized.properties" to
"project.properties"  project.properties should have following value.

logDirectory==/application/logs
installDir=/application/config

I saw maven replace plugin is not sufficient for this ?

I can use ANT to perform this task but I donot want to use ANT inside MAVEN.

Any one has better approach for this.










--
View this message in context: http://maven.40175.n5.nabble.com/Replacing-properties-with-Maven-tp4936132p4936132.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


Re: Replacing properties with Maven.

Posted by MavenUser8979 <mi...@yahoo.com>.
Thanks for your valuable help. This can be achived with  out ANT. 

My goal is to migrate my project from ANT to MAVEN and donot want to use ANT
for this Proof of concept.

Given below are steps. Hope it will help some one.

1) Load all the properties in initialize phase using POM properties plugin.

   <plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>properties-maven-plugin</artifactId>
	<version>1.0-alpha-1</version>
	<executions>
		<execution>
		<phase>initialize</phase>
		<goals>
		     <goal>read-project-properties</goal>
		</goals>
		<configuration>
			<files>
		                <file>local/global.properties</file>
			</files>
		</configuration>
		</execution>
	</executions>
 </plugin>

2) Use POM's resource plugin with copy resource goal (process resource is
having some issue not sure)
    during Validate phase.

   <artifactId>maven-resources-plugin</artifactId>
   <version>2.5</version>
   <executions>
       <execution>
	<id>copy-resources</id>
	
	<phase>validate</phase>
	    <goals>
		<goal>copy-resources</goal>
	   </goals>
	<configuration>
							<outputDirectory>target/classpath</outputDirectory>
	<resources>
	<resource>
									<directory>classpath</directory>
									<filtering>true</filtering>
	</resource>
	</resources>
	</configuration>
     </execution>
  </executions>
</plugin>

This will replace all the tokens from local/global.properties file to
classpath/*.* files.

Thanks.

   

--
View this message in context: http://maven.40175.n5.nabble.com/Replacing-properties-with-Maven-tp4936132p4942457.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


Re: Replacing properties with Maven.

Posted by Wayne Fay <wa...@gmail.com>.
> I can use ANT to perform this task but I donot want to use ANT inside MAVEN.

Why not? This is perfectly acceptable to most pragmatic users of Maven...

Wayne

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


Re: Replacing properties with Maven.

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, Oct 25, 2011 at 9:09 AM, MavenUser8979 <mi...@yahoo.com> wrote:

> I have one requirement where I want to read all the parameterized
> properties
> from one file and replace it in other file.


Hello!  I'm sorry you've gotten such short answers.  I'll see if I can be of
more help.

Property replacement is already available in Maven in two places:

   - As part of the resources mechanism in the POM (details here:
   http://www.sonatype.com/books/mvnref-book/reference/resource-filtering-sect-description.html
   )
   - Programmatically, as part of the maven-resources-plugin's copyResources
   goal (details here:
   http://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html
   )

Besides those, you can of course use the maven-replacer-plugin (though I
don't really see it being any better than just straight resource filtering
for the problem you've described), or do properties replacement in Ant
(though that seems overkill, as you suggest).

Let's start there and see if either of those two approaches helps you out.
If not, we'll need more details about your project layout.

Good luck!

Best,
Laird

-- 
http://about.me/lairdnelson

Re: Replacing properties with Maven.

Posted by Ansgar Konermann <an...@googlemail.com>.
Am 25.10.2011 16:37 schrieb "MavenUser8979" <mi...@yahoo.com>:
>
> All,
>
> I have one requirement where I want to read all the parameterized
properties
> from one file and replace it in other file.
>
> e.g.
>
> parameterized.properties is having below two properties.
>
> LOG_DIR=/application/logs
> INSTALL_DIR = /application/config
>
> Now I have other property file project.properties with below two
properties.
>
> logDirectory=@LOG_DIR@
> installDir=@INSTALL_DIR@
>
> After I replace strings from "parameterized.properties" to
> "project.properties"  project.properties should have following value.
>
> logDirectory==/application/logs
> installDir=/application/config
>
> I saw maven replace plugin is not sufficient for this ?

Can't see why it should't. Can you explain?

>
> I can use ANT to perform this task but I donot want to use ANT inside
MAVEN.
>
> Any one has better approach for this.

Replace plugin should be fine. Properties plugin also.

Regards

Ansgar

>
>
>
>
>
>
>
>
>
>
> --
> View this message in context:
http://maven.40175.n5.nabble.com/Replacing-properties-with-Maven-tp4936132p4936132.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
>