Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Maven不读取应用程序属性文件_Java_Spring_Maven_Maven 2_Maven Resources Plugin - Fatal编程技术网

Java Maven不读取应用程序属性文件

Java Maven不读取应用程序属性文件,java,spring,maven,maven-2,maven-resources-plugin,Java,Spring,Maven,Maven 2,Maven Resources Plugin,我试图在我的包中引入属性文件(基于OSGI的Spring动态模块)。我想在该属性文件中保留数据库URL、用户名、密码等属性,并希望maven从该文件中读取 我尝试在我的pom中引入过滤: <properties> <database.username>${development_user}</database.username> </properties> <build> <filters>

我试图在我的包中引入属性文件(基于OSGI的Spring动态模块)。我想在该属性文件中保留数据库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>
但是,当我使用命令“mvn clean install-Denv=local”通过bundle构建时,系统会在我的database.xml中插入“${development\u user}”作为值

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

试试这个

        <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>

org.codehaus.mojo
属性maven插件
1.0-α-2
阅读
验证
读取项目属性
src/main/resources/Application_${env}.properties

database.xml是否位于src/main/resources中?
        <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>