gpt4 book ai didi

java - 加载属性文件时出错(插件 :maven-war-plugin:2. 4:war:default-war:package)

转载 作者:行者123 更新时间:2023-11-30 07:38:54 30 4
gpt4 key购买 nike

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

我收到的错误如下:

Error loading property file 'E:\Development\CodeSource\GitHub\myproject\profiles\dev\mongo.properties' (org.apache.maven.plugins:maven-war-plugin:2.4:war:default-war:package)

属性文件的实际位置是:

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。

最佳答案

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

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

关于java - 加载属性文件时出错(插件 :maven-war-plugin:2. 4:war:default-war:package),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34963814/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com