如何从文件中创建maven查找属性

时间:2013-01-18 17:24:13

标签: java spring maven maven-3

我正在尝试让maven从像〜/ home / user / file.prop这样的文件中加载我的属性。有人可以告诉我如何更改以下pom以支持本地配置文件被调用如何从文件中获取它们

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.uftwf</groupId>
    <artifactId>MavenJbossWebDemo</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>Maven and JBoss WebDemo Webapp</name>
    <url>http://maven.apache.org</url>


    <properties>
        <java-version>1.7</java-version>
    </properties>
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <deploy.jboss.host>10.52.17.21</deploy.jboss.host>
                <deploy.jboss.user>admin</deploy.jboss.user>
                <deploy.jboss.password>redhat</deploy.jboss.password>
            </properties>
        </profile>

        <profile>
            <id>local</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <deploy.jboss.host>127.0.0.1</deploy.jboss.host>
                <deploy.jboss.user>xxx</deploy.jboss.user>
                <deploy.jboss.password>xxx</deploy.jboss.password>
            </properties>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>MavenJbossWebDemo</finalName>

        <plugins>
            <plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <version>7.2.Final</version>
                <configuration>
                    <hostname>${deploy.jboss.host}</hostname>
                    <port>${deploy.jboss.port}</port>
                    <username>${deploy.jboss.user}</username>
                    <password>${deploy.jboss.password}</password>
                </configuration>
                <executions>
                    <execution>
                        <id>deploy-jar</id>
                        <phase>install</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

1 个答案:

答案 0 :(得分:4)

我认为Properties Maven插件可能有所帮助。查看其usage example