【发布时间】:2019-04-05 16:28:11
【问题描述】:
我正在尝试使用 Maven 为我的项目设置集成测试环境,但在运行 Compile 目标时出现以下错误。
[ERROR] 未能执行目标 org.apache.maven.plugins:maven-resources-plugin:3.0.2:resources 项目mavenintegrationtest上的(默认资源):加载错误 属性文件 '/Users/xxx/dev/poc/java/mavenintegrationtest/profiles/dev/config.properties' -> [帮助 1]
错误似乎是在抱怨它无法在该位置找到正确的 config.properties 文件。出于某种原因,它从文件路径中删除了“src/main/resources”位。
所以正确的完整路径是,
/Users/xxx/dev/poc/java/mavenintegrationtest/src/main/resources/profiles/dev/config.properties
但由于某种原因,它删除了 src/main/resources ,所以正在查看,
/Users/xxx/dev/poc/java/mavenintegrationtest/profiles/dev/config.properties
有谁知道这是什么原因造成的?
我的 POM 如下所示,当我取消注释以下“过滤器”标签时出现此错误,
<filter>${basedir}/profiles/${build.profile.id}/config.properties</filter>
我已尝试删除 ${basedir} 语句,但仍然出现相同的错误。
<?xml version="1.0" encoding="UTF-8"?>
<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>com.stackoverflow</groupId>
<artifactId>mavenintegrationtest</artifactId>
<version>1.0-SNAPSHOT</version>
<name>mavenintegrationtest</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<filters>
<filter>${basedir}/profiles/${build.profile.id}/config.properties</filter>
</filters>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
</build>
<!-- Profile configuration -->
<profiles>
<!-- The configuration of the development profile -->
<profile>
<id>dev</id>
<!-- The development profile is active by default -->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<build.profile.id>dev</build.profile.id>
</properties>
</profile>
<!-- The configuration of the integration-test profile -->
<profile>
<id>integration-test</id>
<properties>
<build.profile.id>integration-test</build.profile.id>
</properties>
</profile>
</profiles>
</project>
【问题讨论】:
-
当你说你删除了 ${basedir} 部分时,我猜你也删除了前导 / 并且只留下了“src/main/resources”?
-
您没有关于错误消息的更多信息吗?
-
@Sxilderik 是的,这是正确的,我试过只用“src/main/resources”运行
-
@lpinto.eu 我尝试打开调试跟踪,然后得到一个“FileNotFound”异常消息,它很清楚 - 它找不到我的 config.properties 文件,因为它删除了“src/main/路径中的资源”位....我不明白是什么原因造成的。
-
您的根项目中没有配置文件文件夹。尽管 maven 期待一个,因为您在过滤器部分中指定了它。
标签: java maven-3 maven-plugin maven-surefire-plugin