title: Java file: Content not allowed in prolog
body: <p>I'm new to Spring and started using the Sprint Tool Suite (eclipse) and see this error in a java file in my maven project: "Content is not allowed in prolog".  This prevents the class from compiling (which is just a minimal SpringBootApplication class) in eclipse.</p>
  
  <pre><code>package com.test;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class Application {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>I've scoured the web and saw that in virtually every reference, this is an XML-parsing error.  I had been updating three XML files but didn't see any invisible characters before the <code>&lt;?xml</code> in a hex editor.  They all specify to use UTF-8 encoding and I'm not seeing alternating 0 bytes that would indicate an accidental UTF-16 encoding.  The line endings seem consistent (just a line feed).</p>
  
  <p>Interestingly, it builds without compiler errors with "maven clean install".  I don't see any special characters in the java file either, but eclipse tells me that file is the problem and that's it a spring beans problem. The error message shows on the first line with the package statement.</p>
  
  <p>Any ideas what the root problem is or how I can solve this?</p>
  
  <p><strong>Update</strong>
  As requested, here's my pom.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;gs-rest-service&lt;/artifactId&gt;
      &lt;version&gt;0.1.0&lt;/version&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.2.5.RELEASE&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mybatis&lt;/groupId&gt;
              &lt;artifactId&gt;mybatis&lt;/artifactId&gt;
              &lt;version&gt;3.2.8&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
         &lt;resources&gt;
           &lt;resource&gt;
             &lt;targetPath&gt;com/test/mybatis/mappers&lt;/targetPath&gt;
             &lt;directory&gt;src/main/java/com/test/mybatis/mappers&lt;/directory&gt;
             &lt;includes&gt;
               &lt;include&gt;*.xml&lt;/include&gt;
             &lt;/includes&gt;
           &lt;/resource&gt;
           &lt;resource&gt;
             &lt;directory&gt;src/main/resources&lt;/directory&gt;
           &lt;/resource&gt;
         &lt;/resources&gt;
      &lt;/build&gt;
  
      &lt;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-releases&lt;/id&gt;
              &lt;url&gt;https://repo.spring.io/libs-release&lt;/url&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
      &lt;pluginRepositories&gt;
          &lt;pluginRepository&gt;
              &lt;id&gt;spring-releases&lt;/id&gt;
              &lt;url&gt;https://repo.spring.io/libs-release&lt;/url&gt;
          &lt;/pluginRepository&gt;
      &lt;/pluginRepositories&gt;
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;mysql&lt;/groupId&gt;
                  &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
                  &lt;version&gt;5.1.36&lt;/version&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>Update 2</strong>
  I searched my project folder for all .xml files and have removed all invisible characters programmatically using <code>perl -i -pe 's/[^\x20-\x7f\x0A\x09]//g' fileName</code>, but there were no invisible characters.   This confirms what I saw in the hex editor.</p>
  
  <p><strong>Two questions come to mind:  Why is the error showing in a .java file instead of a. xml file?  Why is this only a problem for eclipse and not maven?</strong></p>
  
  <p>The eclipse log shows this message (which indicates a .xml file):</p>
  
  <pre><code>org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
      at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
      at org.springframework.ide.eclipse.core.io.xml.XercesDocumentLoader.loadDocument(XercesDocumentLoader.java:48)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
      at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.loadBeanDefinitions(BeansConfig.java:397)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
      at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:456)
      at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:1)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p><strong>Update 3</strong>
  I did find some eclipse-generated xml files in my workspace with characters before the <code>&lt;?xml</code> using <code>grep -ERl '^[^=]+&lt;\?xml' .</code> which ignores some of the eclipse user prefs which have xml embedded in the lines of the file.  After removing the extra characters, the problem remained though.</p>
  
  <p>Think I may restart the project and copy over files one at a time.   </p>