Maven:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources

后端 未结 10 734
渐次进展
渐次进展 2020-12-05 06:34

I am building my project using Maven. My maven version is apache-maven-3.0.4. I am using Eclipse Luna. When I try to build my project I get the following error

相关标签:
10条回答
  • 2020-12-05 06:46

    I had this issue too because I was filtering /src/main/resources and forgot I had added a keystore (*.jks) binary to this directory.

    Add a "resource" block with exclusions for binary files and your problem may be resolved.

    <build>
      <finalName>somename</finalName>
      <testResources>
        <testResource>
          <directory>src/test/resources</directory>
          <filtering>false</filtering>
        </testResource>
      </testResources>
      <resources>
        <resource>
          <directory>src/main/resources</directory>
          <filtering>true</filtering>
          <excludes>
            <exclude>*.jks</exclude>
            <exclude>*.png</exclude>
          </excludes>        
        </resource>
      </resources>
    ...
    
    0 讨论(0)
  • What worked for me is to add include tag in order to specify exactly what I want to filter.

    It seems the resource plugin has problems going through the whole src/main/resource folder, probably due to some specific files inside.

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>application.yml</include>
                </includes>
            </resource>
        </resources>
    
    0 讨论(0)
  • 2020-12-05 06:46

    In my case the targetPath was not having any value it was blank in the resources --> resource for the file directory with files that had issue. I had to update it to global as seen in the Code Sample 2 and re-run build to fix the issue.

    Code Sample 1 (with issue)

    <build>
        <resources>
            <resource>
                <directory>src/main/locale</directory>
                <filtering>true</filtering>
                <targetPath></targetPath>
                <includes>
                    <include>*.xml</include>
                    <include>*.config</include>
                    <include>*.properties</include>
                </includes>
            </resource>
        </resources>
    

    Code Sample 2 (fix applied)

    <build>
        <resources>
            <resource>
                <directory>src/main/locale</directory>
                <filtering>true</filtering>
                <targetPath>global</targetPath>
                <includes>
                    <include>*.xml</include>
                    <include>*.config</include>
                    <include>*.properties</include>
                </includes>
            </resource>
        </resources>
    

    0 讨论(0)
  • 2020-12-05 06:47

    From official documentation

    Warning: Do not filter files with binary content like images! This will most likely result in corrupt output.

    If you have both text files and binary files as resources it is recommended to have two separated folders. One folder src/main/resources (default) for the resources which are not filtered and another folder src/main/resources-filtered for the resources which are filtered.

    <project>
      ...
      <build>
        ...
        <resources>
          <resource>
            <directory>src/main/resources-filtered</directory>
            <filtering>true</filtering>
          </resource>
          ...
        </resources>
        ...
      </build>
      ...
    </project>
    

    Now you can put those files into src/main/resources which should not filtered and the other files into src/main/resources-filtered.

    As already mentioned filtering binary files like images,pdf`s etc. could result in corrupted output. To prevent such problems you can configure file extensions which will not being filtered.

    Most certainly, You have in your directory files that cannot be filtered. So you have to specify the extensions that has not be filtered.

    0 讨论(0)
  • 2020-12-05 06:53

    I faced the same problem and did the filtering false like below working for me. You can try the same...

    <testResources>
        <testResource>
            <directory>src/test/java</directory>
            <filtering>false</filtering>
        </testResource>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>false</filtering>
        </testResource>
    </testResources>
    
    0 讨论(0)
  • 2020-12-05 06:57

    in my case, it was a confilict with IntelliJ , I've resolved it by building the project from command line and it worked!

    0 讨论(0)
提交回复
热议问题