首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误加载属性文件(plugins:maven-war-plugin:2.4:war:default-war:package)

错误加载属性文件(plugins:maven-war-plugin:2.4:war:default-war:package)
EN

Stack Overflow用户
提问于 2016-01-23 13:06:41
回答 1查看 2.4K关注 0票数 1

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

我收到的错误如下:

错误加载属性文件'E:\Development\CodeSource\GitHub\myproject\profiles\dev\mongo.properties‘(org.apache.maven.plugins:maven-war-plugin:2.4:war:default-war:package)

属性文件的实际位置是:

代码语言:javascript
复制
E:\Development\CodeSource\GitHub\myproject\src\main\resources\profiles\dev\mongo.properties

因此,我将资源位置设置为:

代码语言:javascript
复制
<resources>
    <resource>
        <filtering>true</filtering>
        <directory>src/main/resources</directory>
    </resource>
</resources>

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

下面是整个pom文件:

代码语言:javascript
复制
<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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-23 13:39:08

筛选器文件的路径是src/main/resources。因此,您需要像这样配置它:

代码语言:javascript
复制
<filters>
    <filter>src/main/resources/profiles/${build.profile.id}/mongo.properties</filter>
</filters>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34963814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档