Question

I’m using Maven 3.1.0. I have a file like so

driver:    com.mysql.jdbc.Driver
url:       jdbc:mysql://localhost:3306/db
username:  user
password:  pass

Is there a way I can get Maven to parse this file so that I can use the keys (e.g. “username”) as properties (e.g. ${username}) in other parts of my Maven script? Ultimately I want to pass these properties as connection parameters to the Maven SQL plugin.

Unfortunately, its not an option to change the format of this file.

Was it helpful?

Solution

Take a look at the Properties Maven 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>myconfig.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

The plugin should be able to handle your properties file. if not (format problems), you could include a build step to convert the file to a more convenient format.

OTHER TIPS

EnvInject Plugin used to inject Variables from property files. Refer https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top