Home > Dev Stuffs, Java, maven > Maven write an properties file

Maven write an properties file


Maven

Hi there, still going with Maven issues.

In a previous post I mentioned about how make your app read files from a properties file. But, this is not enough to my requirements, what I need:

  • Default properties file – with all values from our CI enviroment
  • Developer properties file – Each developer need to create a personal file re-writing some files like, database_host
  • The output file shall be on specific directory – In my project I need the properties file under: ${basedir}/src/main/resources/app.properties

So this is my solution:

<!-- ************************************************************** 
	MAKE POSSIBLE TO RUN CREATE A PROPERTIES FILE BASED 
	ON default.propertes filtered by user.name.properties
    ************************************************************** -->
	<plugin>
		<groupId>org.codehaus.mojo</groupId>
		<artifactId>properties-maven-plugin</artifactId>
		<version>1.0-alpha-2</version>
		<executions>
			<execution>
				<phase>initialize</phase>
				<goals>
					<goal>write-project-properties</goal>
				</goals>
				<configuration>
					<outputFile>${basedir}/src/main/resources/myApp.properties</outputFile>
				</configuration>
			</execution>
		</executions>
	</plugin>
	<plugin>
		<groupId>org.codehaus.mojo</groupId>
		<artifactId>properties-maven-plugin</artifactId>
		<version>1.0-alpha-2</version>
		<executions>
			<execution>
				<phase>initialize</phase>
				<goals>
					<goal>read-project-properties</goal>
				</goals>
				<configuration>
					<files>
						<file>properties/default.properties</file>
						<file>properties/${user.name}.properties</file>
					</files>
				</configuration>
			</execution>
		</executions>
	</plugin>

Important points:

  • I don’t know yet why the ORDER of this two plugins are important, but it is. I’ll do some tests to check this!
  • If you have any Unit Test that need the output file done, inside your eclipse you will need to run: >mvn initialize

That’s it for now…

Any questions? Leave a comment! Just click UP there on Leave a comment

Cheers

  1. 2013.April.25 at 05:41

    Hurrah, that’s what I was seeking for, what a material! existing here at this webpage, thanks admin of this web page.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: