Maven Compile无法找到src / main / resources目录

问题描述 投票:0回答:1

我正在尝试使用Maven为我的项目设置集成测试环境,但在运行Compile目标时遇到以下错误。

[错误]无法执行目标org.apache.maven.plugins:maven-resources-plugin:3.0.2:项目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>

enter image description here

java maven-3 maven-plugin maven-surefire-plugin
1个回答
1
投票

filterlink)元素将解析您的文件并对其应用内容过滤器。 profileslink)元素可帮助您为构建定义不同的环境。

所有这些都与您的资源有关。这些可以是配置文件或其他类型的文件。如果您进行过滤,则可以使用其他值更改此文件的内容 - 例如pom属性。使用配置文件时,您可以为每个环境使用不同的替换属性。

您应该在树中向上移动配置文件以获取默认路径,或者在您的pom中为资源位置添加配置。 base dir是包含你的pom的文件夹。你应该在这里有你的个人资料文件夹

My own example

此外,here是关于配置文件及其配置的一些很好的信息。

© www.soinside.com 2019 - 2024. All rights reserved.