我试图让 properties-maven-plugin 从我的 .properties 文件中读取。Flyway(我试图使用属性)只是不断抛出关于 db url 格式错误的错误,但如果我在 pom.xml 本身中设置值,而不是使用从文件中读取的属性,则可以工作。
我将 eclipse 与 m2e 插件一起使用。
从 .properties 读取的插件配置
<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>src/main/resources/config.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
使用属性的 Flyway 配置
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>flyway:migrate</goal>
</goals>
</execution>
</executions>
<configuration>
<driver>${db.driver}</driver>
<url>${db.url}</url>
<user>${db.user}</user>
<password>${db.password}</password>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
</dependencies>
</plugin>
config.properties 位于 /src/main/resources/
# Database details
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/dbname
db.user=username
db.pass=password
我尝试查看其他几个 stackoverflow 线程,但似乎没有一个解决方案有效。我是 maven 的新手,整个事情似乎都让我失望了,有人有灯吗?