关于java:Maven:无法执行目标org.apache.maven.plugins:maven-resources-plugin:2.7:resources

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

我正在使用Maven构建项目。 我的Maven版本是apache-maven-3.0.4。 我正在使用Eclipse Luna。 当我尝试构建项目时,出现以下错误

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources (default-resources) on project OrionCommunity: Mark invalid -> [Help 1].

以下是我运行mvn clean install -X时的堆栈跟踪:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:53.295s
[INFO] Finished at: Thu Oct 09 20:00:26 IST 2014
[INFO] Final Memory: 9M/25M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources (default-resources) on project OrionCommunity: Mark invalid -> [Hel
p 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources (default-resources)
 on project OrionCommunity: Mark invalid
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Mark invalid
        at org.apache.maven.plugin.resources.ResourcesMojo.execute(ResourcesMojo.java:306)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more
Caused by: org.apache.maven.shared.filtering.MavenFilteringException: Mark invalid
        at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile(DefaultMavenFileFilter.java:129)
        at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources(DefaultMavenResourcesFiltering.java:264)
        at org.apache.maven.plugin.resources.ResourcesMojo.execute(ResourcesMojo.java:300)
        ... 21 more
Caused by: java.io.IOException: Mark invalid
        at java.io.BufferedReader.reset(BufferedReader.java:485)
        at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read(MultiDelimiterInterpolatorFilterReaderLineEnding.java:416)
        at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read(MultiDelimiterInterpolatorFilterReaderLineEnding.java:205)
        at java.io.Reader.read(Reader.java:123)
        at org.apache.maven.shared.utils.io.IOUtil.copy(IOUtil.java:181)
        at org.apache.maven.shared.utils.io.IOUtil.copy(IOUtil.java:168)
        at org.apache.maven.shared.utils.io.FileUtils.copyFile(FileUtils.java:1856)
        at org.apache.maven.shared.utils.io.FileUtils.copyFile(FileUtils.java:1804)
        at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile(DefaultMavenFileFilter.java:114)
        ... 23 more

我的Maven存储库位于D:/ mavenrepo下。 我已经完全删除了回购中存在的所有jar,并进行了全新安装。 但是我仍然会收到此错误。


带有:

1
2
3
4
5
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
            maven-resources-plugin</artifactId>
            <version>2.7</version>
        </plugin>

正在收到以下异常:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
Caused by: org.apache.maven.plugin.MojoExecutionException: Mark invalid
    at org.apache.maven.plugin.resources.ResourcesMojo.execute(ResourcesMojo.java:306)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 25 more
Caused by: org.apache.maven.shared.filtering.MavenFilteringException: Mark invalid
    at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile(DefaultMavenFileFilter.java:129)
    at org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering.filterResources(DefaultMavenResourcesFiltering.java:264)
    at org.apache.maven.plugin.resources.ResourcesMojo.execute(ResourcesMojo.java:300)
    ... 27 more
Caused by: java.io.IOException: Mark invalid
    at java.io.BufferedReader.reset(BufferedReader.java:505)
    at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read(MultiDelimiterInterpolatorFilterReaderLineEnding.java:416)
    at org.apache.maven.shared.filtering.MultiDelimiterInterpolatorFilterReaderLineEnding.read(MultiDelimiterInterpolatorFilterReaderLineEnding.java:205)
    at java.io.Reader.read(Reader.java:140)
    at org.apache.maven.shared.utils.io.IOUtil.copy(IOUtil.java:181)
    at org.apache.maven.shared.utils.io.IOUtil.copy(IOUtil.java:168)
    at org.apache.maven.shared.utils.io.FileUtils.copyFile(FileUtils.java:1856)
    at org.apache.maven.shared.utils.io.FileUtils.copyFile(FileUtils.java:1804)
    at org.apache.maven.shared.filtering.DefaultMavenFileFilter.copyFile(DefaultMavenFileFilter.java:114)
    ... 29 more

然后在添加了maven-filtering 1.3之后就消失了:

1
2
3
4
5
6
7
8
9
10
11
12
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
            maven-resources-plugin</artifactId>
            <version>2.7</version>
          <dependencies>
            <dependency>
                <groupId>org.apache.maven.shared</groupId>
                maven-filtering</artifactId>
                <version>1.3</version>
            </dependency>
          </dependencies>
        </plugin>


为我删除此工作:

1
<filtering>true</filtering>

我猜这是由这个过滤错误引起的


我也有这个问题,因为我正在过滤/ src / main / resources并忘记了我已经向该目录添加了密钥库(* .jks)二进制文件。

添加带有二进制文件排除项的"资源"块,可能会解决您的问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<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>
...

对我有用的是添加include标记,以便确切指定我要过滤的内容。

似乎资源插件在遍历整个src / main / resource文件夹时出现问题,可能是由于其中包含一些特定文件所致。

1
2
3
4
5
6
7
8
9
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>application.yml</include>
            </includes>
        </resource>
    </resources>

从官方文件

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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.

最肯定的是,您的目录中包含无法过滤的文件。因此,您必须指定尚未过滤的扩展名。


在我的情况下,targetPath没有任何值,对于文件directory中的resources --> resource,空白的文件带有问题。
Code Sample 2所示,我不得不将其更新为global,然后重新运行构建以解决此问题。

代码示例1(有问题)

1
2
3
4
5
6
7
8
9
10
11
12
13
<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>

代码示例2(已应用修复)

1
2
3
4
5
6
7
8
9
10
11
12
13
<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>


就我而言,这是与IntelliJ的冲突,我已经通过从命令行构建项目来解决了该问题,并且有效!


我遇到了同样的问题,并且像下面这样为我做过滤错误。
您可以尝试相同的...

1
2
3
4
5
6
7
8
9
10
<testResources>
    <testResource>
        <directory>src/test/java</directory>
        <filtering>false</filtering>
    </testResource>
    <testResource>
        <directory>src/test/resources</directory>
        <filtering>false</filtering>
    </testResource>
</testResources>