【发布时间】:2013-12-08 02:07:13
【问题描述】:
我有一个 maven 项目,我想在事情发生时从文件中加载属性。我有 codehaus properties-maven-plugin,我需要它自动运行。
如果我运行mvn test 或mvn compile,任务插件加载属性文件就好了。
我在输出中看到了这个:
[INFO] --- properties-maven-plugin:1.0-alpha-2:read-project-properties (default)...---
当我运行mvn flyway:init 时,比如说,我没有看到它运行并且属性没有被加载。
这里是 pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.foo</groupId>
<artifactId>workflow</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Foo Framework</name>
<description>Foo framework</description>
<properties>
<postgre.version>9.1-901.jdbc4</postgre.version>
<flyway.version>2.2.1</flyway.version>
</properties>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgre.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<url>${url}</url>
<user>${user}</user>
<password>${pass}</password>
<locations>
<location>classpath:sql/pgsql</location>
</locations>
</configuration>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgre.version}</version>
</dependency>
</dependencies>
</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>src/main/resources/db.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
谁能建议我可以做什么,或者我可以阅读一些文档来完成这项工作?我已经阅读了大量的 Maven 文档,但似乎无法很好地理解它来实现这一点。我以为我在这里的东西可以让它在initialize 阶段运行,但显然不是......
【问题讨论】:
标签: java maven properties pom.xml