加载属性文件时出错(插件:maven-war-plugin:2.4:war:default-war:package)

时间:2016-01-23 13:06:42

标签: java maven maven-war-plugin

我想根据配置文件(devprod配置属性文件,但是未正确构造属性文件的位置。我已经在SO上找到了类似问题的答案,但这些答案都没有帮助解决这个问题。

我收到的错误如下:

  

加载属性文件时出错' E:\ Development \ CodeSource \ GitHub \ myproject \ profiles \ dev \ mongo.properties' (org.apache.maven.plugins:行家-战争插件:2.4:战争:默认战:封装)

属性文件的实际位置是:

E:\Development\CodeSource\GitHub\myproject\src\main\resources\profiles\dev\mongo.properties

所以我按如下方式设置资源位置:

<resources>
    <resource>
        <filtering>true</filtering>
        <directory>src/main/resources</directory>
    </resource>
</resources>

尽管如此,它仍然找不到属性文件。

以下是整个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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>abc.myproject</groupId>
<artifactId>myartifact</artifactId>
<packaging>war</packaging>
<version>0.1.0-SNAPSHOT</version>

<name>projectname</name>
<description>Site Description</description>
<url>http://www.myproject.abc</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <maven-war-plugin.version>2.4</maven-war-plugin.version>
    <tomcat-deploy-path>output</tomcat-deploy-path>
</properties>

<dependencies>
    // various dependencies
</dependencies>

<build>
    <finalName>v${project.artifactId}#${project.version}</finalName>
    <filters>
        <filter>profiles/${build.profile.id}/mongo.properties</filter>
    </filters>
    <resources>
        <resource>
            <filtering>true</filtering>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>${maven-war-plugin.version}</version>
            <configuration>
                <outputDirectory>${tomcat-deploy-path}</outputDirectory>
                <failOnMissingWebXml>true</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
            </configuration>
        </plugin>
    </plugins>
</build>


<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <build.profile.id>dev</build.profile.id>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <build.profile.id>prod</build.profile.id>
        </properties>
    </profile>
</profiles>

</project>

我正在使用Eclipse。

1 个答案:

答案 0 :(得分:1)

过滤器文件的路径为relative to the project root, not to src/main/resources。因此,您需要像这样配置它:

<filters>
    <filter>src/main/resources/profiles/${build.profile.id}/mongo.properties</filter>
</filters>