Java 学习 Maven:jar 插件的“无法解析配置”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20735122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:55:28  来源:igfitidea点击:

Learning Maven: "Unable to parse configuration" for jar plugin

javaeclipsemavenjar

提问by arcy

I am attempting to learn maven on a small project of my own, using eclipse. I converted the existing project to the maven standard directory configuration, and it was building; now I'm trying to get maven to produce the jar for the application. The following is pom.xml:

我正在尝试使用 eclipse 在我自己的一个小项目中学习 maven。我将现有项目转换为maven标准目录配置,正在build中;现在我正在尝试让 maven 为应用程序生成 jar。以下是 pom.xml:

<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.rc          </groupId>
    <artifactId>    SpaceCheck      </artifactId>
    <version>       0.9.1-SNAPSHOT  </version>
    <name>          SpaceCheck      </name>
    <packaging>     jar             </packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
              <plugin>
                  <groupId>   org.apache.maven.plugins </groupId>
                  <artifactId>maven-jar-plugin         </artifactId>
                  <version>   2.3.2                    </version>
                  <configuration>
                <includes>**/src/*</includes>
                      <archive>
                          <manifest>
                              <addClasspath>true</addClasspath>
                              <classpathPrefix>lib/</classpathPrefix>
                              <mainClass>spacecheck.SpaceCheck</mainClass>
                          </manifest>
                      </archive>
                  </configuration>
              </plugin>
        </plugins>
    </build>

</project>

I didn't use to have the 'includes' clause; as near as I can tell, that's what the example I got pointed to told me to do to fix the problem. It does not.

我以前没有“包含”子句;就我所知,这就是我指出的示例告诉我要解决问题的方法。它不是。

When I attempt to build, I get:

当我尝试构建时,我得到:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar (default-jar) on project SpaceCheck: Unable to parse configuration of mojo org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar for parameter includes: Cannot assign configuration entry 'includes' with value '*/src/' of type java.lang.String to property of type java.lang.String[] -> [Help 1]

[错误] 无法在项目 SpaceCheck 上执行目标 org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar (default-jar):无法解析 mojo org.apache.maven.plugins:maven 的配置-jar-plugin:2.3.2:jar 参数包含:无法将java.lang.String 类型的值为 '* /src/' 的配置条目 'includes' 分配给java.lang.String[] 类型的属性 -> [帮助 1]

The "Help 1" link points me to the tutorial that I followed to get this far.

“帮助 1”链接将我指向我遵循的教程。

The problem I have with the tutorial is that it doesn't explain how things work -- it gives you an example and expects you to extract general workings from the example. There's nothing wrong with examples, but they rarely match exactly what one wants to do.

我在本教程中遇到的问题是它没有解释事情是如何工作的——它为您提供了一个示例,并希望您从示例中提取一般工作原理。示例没有任何问题,但它们很少与人们想要做的完全匹配。

I'm sure many people can tell me what's wrong, and I would appreciate it. But it would be even better if they could ALSO tell me where this is explained, not just where there is an example that does something similar. The explanation, to be complete, would explain what element needs to be added, just where in the XML that goes, and what the various options are for the thing that goes there.

我相信很多人都可以告诉我出了什么问题,我将不胜感激。但是,如果他们还可以告诉我这是在哪里解释的,而不仅仅是哪里有类似的例子,那就更好了。完整的解释将解释需要添加什么元素,在 XML 中的位置,以及在那里的事物的各种选项是什么。

回答by Robert Scholte

Since you're asking for the documentation (and not the direct answer), have a look at http://maven.apache.org/guides/mini/guide-configuring-plugins.html

由于您要求提供文档(而不是直接答案),请查看http://maven.apache.org/guides/mini/guide-configuring-plugins.html

回答by Joachim Rohde

Instead of

代替

<includes>**/src/*</includes>

try

尝试

<includes>
    <include>**/src/*</include>
</includes>

And if you are learning Maven you definitely want to check out The Complete Reference.

如果您正在学习 Maven,您肯定想查看The Complete Reference

回答by suraj.tripathi

The problem is maven version

问题是maven版本

Following format for list/set is support in maven 3.3.9and onward versions but in lower versions it not supported.

maven3.3.9及以后版本支持列表/集合的以下格式,但在较低版本中不支持。

<includes>**/src/*</includes>

But in maven version less than 3.3.9, above is not supported

但是在低于 的Maven 版本中3.3.9,不支持以上版本

To fix make it backward compatible

修复使其向后兼容

<includes>
    <include>**/src/*</include>   
</includes>

PS: for more details check thislink

PS:欲了解更多详情,请查看链接