<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?
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.
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.
properties file in the maven project folder src/main/resources`. In pom. xml, add resources inside the building element and set filtering=true.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With