Java maven 错误:元素依赖不能有子元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26508166/
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
maven error: element dependency can not have character children
提问by Rob
I'm not sure what happened, but the POM for my project no longer works. Its complaining about the dependency element. Is it that the dependency no longer exists? What does this error mean? To be clear I haven't change the POM, it just does not work now.
我不确定发生了什么,但我项目的 POM 不再有效。它抱怨依赖元素。是不是依赖已经不存在了?这个错误是什么意思?需要明确的是,我没有更改 POM,它现在不起作用。
The exact error message is cvc-complex-type.2.3: Element 'dependency' cannot have character (children), because this type's content type is element-only.
确切的错误消息是 cvc-complex-type.2.3: 元素 'dependency' 不能有字符(子),因为这种类型的内容类型是仅元素的。
<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.medfusion</groupId>
<artifactId>Estatements-core</artifactId>
<version>14.6.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Estatements-core</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.group.id.Launcher1</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>nexus-qhg-dev</id>
<name>Medfusion repo</name>
<url>http://maven.qhg.local/nexus/content/groups/qhg-dev</url>
</repository>
</repositories>
<dependencies>
<dependency>
? <groupId>com.intuit.health</groupId>
<version>14.6.0-SNAPSHOT</version>
? <artifactId>notification-reference</artifactId> ? ?
</dependency>
<dependency>
? ? ? <groupId>junit</groupId>
? ? ? <artifactId>junit</artifactId>
? ? ? <version>3.8.1</version>
? ? ? <scope>test</scope>
? </dependency>
<dependency>
? ? <groupId>com.intuit.health</groupId>
? <version>ihg-depot-trunk-SNAPSHOT</version>
? <artifactId>attachment-reference</artifactId>
? </dependency>
<dependency>
? <groupId>com.intuit.health</groupId>
? <version>ihg-depot-trunk-SNAPSHOT</version>
? <artifactId>eCommunication-core</artifactId> ? ?
</dependency>
</dependencies>
</project>
采纳答案by ZenLulz
As mentioned in the comment by Powerlord, this error is due to incorrect parsing of the XML file, because there are strange and hidden characters in between a/some <dependency>...</dependency>
tag(s). Those characters could come from a copy paste from the Web.
正如Powerlord的评论中提到的,这个错误是由于 XML 文件的错误解析造成的,因为 a/some<dependency>...</dependency>
标签之间有奇怪的隐藏字符。这些字符可能来自网络的复制粘贴。
To solve the issue, remove all spaces and newline characters between <dependency>...</dependency>
tags definitions and put them back into your editor.
要解决此问题,请删除<dependency>...</dependency>
标签定义之间的所有空格和换行符,然后将它们放回编辑器中。
回答by Nasco
I recently faced that problem and the error showed at the xsi:schemaLocationof the pom.xmlfile and it was a problem of copy and paste from different websites introducing an invisible non-space character. To check which line have the hidden character I take a copy of the pom file and paste it to a blank word file and enable "Show paragraph mark and other formatting".
我最近遇到了这个问题,错误显示在pom.xml文件的xsi:schemaLocation中,这是一个从不同网站复制和粘贴的问题,引入了一个不可见的非空格字符。要检查哪一行有隐藏字符,我复制了 pom 文件并将其粘贴到一个空白的 word 文件中,然后启用“显示段落标记和其他格式”。
回答by Russ Bateman
This is because, as others have said, there are non-printable, but XML-illegal characters inserted into pom.xml, usually between XML elements. In my case, this often happens when I copy and paste from elsewhere, usually documentation, an article, tutorial, etc. in my browser.
这是因为,正如其他人所说,在pom.xml 中插入了不可打印但 XML 非法的字符,通常在 XML 元素之间。就我而言,当我从其他地方复制和粘贴时,通常会发生这种情况,通常是在浏览器中的文档、文章、教程等。
For me, IntelliJ IDEA's editor displays these characters as rose-colored space, perhaps a function of my color scheme, so that it's easy to find and delete them.
对我来说,IntelliJ IDEA 的编辑器将这些字符显示为玫瑰色空间,这可能是我的配色方案的一个功能,以便于查找和删除它们。
回答by Manthan Joshi
It's because you have tried to copy paste the dependencies from the web and there are some special or hidden characters are there which are causing this type of errors. So first copy to a text file then put paste it to the code for avoiding this type of an error.
这是因为您尝试从网络复制粘贴依赖项,并且存在一些导致此类错误的特殊或隐藏字符。因此,首先复制到文本文件,然后将其粘贴到代码中以避免此类错误。