Home > Dev Stuffs, Java, TIP > Maven read an external properties file

Maven read an external properties file


Maven
Hi there,

Back to my project and one more lessons learn, on my study project I need maven to read values from my properties file, values like database host, password and etc…

Maven have a nice plugin called Properties Maven Plugin

Here is the changes on your pom.xml

		<!-- *************** MAVEN PROPERTIES PLUGIN *************** -->
		<dependency>
			<groupId>org.codehaus.mojo</groupId>
			<artifactId>properties-maven-plugin</artifactId>
			<version>1.0-alpha-2</version>
		</dependency>

and…

<build>
    <plugins>
    (...)
        <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>${basedir}/src/main/resources/your.properties</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
    (...)
    </plugin>
(...)

And finally I discover a decent way to post source-code do wordpress!!!!!!!!!!!!!!!!!!!!!!!!!! :)

Advertisement
  1. TH Lim
    2011.December.05 at 05:37 | #1

    Is there is any precondition to this setup? I have parent-child pom.xml setup where I put the properties-maven-plugin in the parent pom. The properties are used in Any idea? Thanks

    Btw, I am using Maven 3.0.3.

  1. 2011.March.03 at 22:29 | #1

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.