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!!!!!!!!!!!!!!!!!!!!!!!!!!ūüôā

  1. TH Lim
    2011.December.05 at 05:37

    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.

  2. 2012.November.08 at 12:32

    Hi, i think that i noticed you visited my website thus i got here to return the want?.I’m trying to in finding issues to enhance my web site!I suppose its adequate to use a few of your ideas!!

  3. 2012.November.29 at 19:42

    You don’t need to declare the dependency on the maven plugin unless you use it at compile time.

    Also, if you want this plugin to be called for your POM make sure you double check what life cycle you bind it to as different types of projects have different life cycle and not all of them call the “initialize” phase. See for example the life cycle for a war project (it has no initialize phase in it)

  1. 2011.March.03 at 22:29

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: