0

我正在尝试在我的包中引入属性文件(基于 Spring Dynamic Modules 的 OSGI)。我想在该属性文件中保留数据库 URL、用户名、密码等属性,并希望 maven 从该文件中读取。

我试图在我的 pom 中引入过滤:

<properties>
    <database.username>${development_user}</database.username>
</properties>
<build>
    <filters> 
         <filter>src/main/resources/Application_${env}.properties</filter> 
    </filters> 
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>bundle</id>
                    <phase>package</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.7</version>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>bundle</id>
                    <phase>package</phase>
                    <goals>
                        <goal>bundle</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <excludes>*/pom.</excludes>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

我的 Application_local.properties 文件中有以下属性:

development_user=dev_user

但是当我使用命令“mvn clean install -Denv=local”通过捆绑构建时,系统会在我的 database.xml 中插入 '${development_user}' 作为值

有人可以帮我解决这个问题吗?

4

1 回答 1

1

试试这个

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0-alpha-2</version>
            <executions>
                <execution>
                    <id>read</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>src/main/resources/Application_${env}.properties</file>
                        </files>
                    </configuration>
                </execution>                   
            </executions>
        </plugin>
于 2014-02-28T10:42:51.687 回答