Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use property file in maven pom.xml for flyway configuration

Tags:

<plugin>     <groupId>com.googlecode.flyway</groupId>     <artifactId>flyway-maven-plugin</artifactId>     <version>1.7</version>     <configuration>         <driver>com.mysql.jdbc.Driver</driver>         <url>jdbc:mysql://127.0.0.1:3306/db_abc</url>         <user>db_user</user>         <sqlMigrationPrefix>V</sqlMigrationPrefix>     </configuration> </plugin> 

I don't want to mention driver, url and user here. I already have a abc.property on src/main/resources. How can use that file here?

like image 492
Garry Avatar asked Sep 27 '12 10:09

Garry


People also ask

What is properties in Maven POM xml?

Maven properties are value placeholders, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. Or they can be used by plugins as default values, for example: In your case you have defined properties as version of java.

Is POM xml a configuration file?

The pom. xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.

Where do you add the xml properties file in the Maven project?

properties file in the maven project folder src/main/resources`. In pom. xml, add resources inside the building element and set filtering=true.


1 Answers

Have a look at the properties-maven-plugin. It allows you to read properties from a file to then use them in your pom.

Add the following plugin defintion:

  <plugin>     <groupId>org.codehaus.mojo</groupId>     <artifactId>properties-maven-plugin</artifactId>     <version>1.0.0</version>     <executions>       <execution>         <phase>initialize</phase>         <goals>           <goal>read-project-properties</goal>         </goals>         <configuration>           <files>             <file>src/main/resources/abc.properties</file>           </files>         </configuration>       </execution>     </executions>   </plugin> 

If abc.properties contains:

jdbc.driver = com.mysql.jdbc.Driver jdbc.url = jdbc:mysql://127.0.0.1:3306/db_ab jdbc.user = db_user 

You can then use the properties as follows:

<!-- language: xml -->  <driver>${jdbc.driver}</driver> <url>${jdbc.url}</url> <user>${jdbc.user}</user> 
like image 198
Sébastien Le Callonnec Avatar answered Sep 19 '22 12:09

Sébastien Le Callonnec