37

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.

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.

<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>
Rob
  • 2,363
  • 7
  • 36
  • 54
  • 1
    If you were missing a dependency, you would be getting a "Missing artifact com.foo.bar" type error. What is the full error text that you are seeing? – azurefrog Oct 22 '14 at 14:12
  • 6
    I don't really want to mark this as a duplicate (as a Gold Java user, it will close it in a single vote), but the [solution is here](http://stackoverflow.com/a/7835746/15880) – Powerlord Oct 23 '14 at 15:01
  • There ended up being something odd in how eclipse was parsing the POM. Cut/paste the whole thing and the error went away. There was no actual error to be clear (there may have been at one time but for whatever reason the parser still showed an error). So try that if you get to this page. – Rob Oct 24 '14 at 18:29
  • I did Select All then Cut then Paste and error went away. Thanks @Rob – Murtuza K Jan 17 '17 at 15:54
  • Possible duplicate of [Problems using Spring Hibernate](https://stackoverflow.com/questions/7835389/problems-using-spring-hibernate) – Marit Jun 02 '18 at 07:54
  • Solution: remove the extra space and check the syntax (possibly in properties tags) – Rishabh Agarwal Nov 01 '19 at 17:59

6 Answers6

103

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.

To solve the issue, remove all spaces and newline characters between <dependency>...</dependency> tags definitions and put them back into your editor.

Rov
  • 133
  • 1
  • 11
Jämes
  • 6,945
  • 4
  • 40
  • 56
  • It worked. It was showing a red line where the hidden character was. I selected all space with red lines and press backspace and the error went away, then pressed ctrl/cmd+shift+f to bring the formatting. – paul Sep 28 '20 at 07:06
  • It worked for me after removing the pasted code and typed myself. Thanks – sam Oct 21 '20 at 09:49
2

I recently faced that problem and the error showed at the xsi:schemaLocation of the pom.xml file 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".

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
Nasco
  • 21
  • 1
2

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.

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.

Russ Bateman
  • 18,333
  • 14
  • 49
  • 65
1

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.

0

This error mainly occurs due to xml parsing error for POM.xml

For me, It was not able to parse xml due to unexpected element '>' after dependencies end tag.

saurabh umathe
  • 315
  • 2
  • 17
0

I get this kind of error without having done copy/paste, only adding dependencies via the Dependencies tab. Select All/Cut/Paste changes the error to "Content is not allowed in trailing section" or ... something I can't seem to reproduce any more. Meanwhile the "Effective POM" tab shows no issues at all.

lordbah
  • 313
  • 1
  • 2
  • 12