2010-09-08 20 views
2

允许我使用GlassFish服务器和以下错误不断来:有关的SAXParseException:内容是不是在序言

Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog. 
     at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:304) 
     at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:226) 
     at com.sun.enterprise.deployment.archivist.Archivist.readStandardDeploymentDescriptor(Archivist.java:480) 
     at com.sun.enterprise.deployment.archivist.Archivist.readDeploymentDescriptors(Archivist.java:305) 
     at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:213) 
     at com.sun.enterprise.deployment.archivist.ApplicationArchivist.openArchive(ApplicationArchivist.java:813) 
     at com.sun.enterprise.instance.WebModulesManager.getDescriptor(WebModulesManager.java:395) 
     ... 65 more 
+2

请提供'<?xml ...'声明和部署描述符的前几行的十六进制转储。 – McDowell 2010-09-08 07:48:48

+0

可能的重复[org.xml.sax.SAXParseException:内容不允许在序言中](http://stackoverflow.com/questions/5138696/org-xml-sax-saxparseexception-content-is-not-allowed-in -prolog) – Raedwald 2014-07-18 09:40:22

回答

4

检查此链接

http://mark.koli.ch/2009/02/resolving-orgxmlsaxsaxparseexception-content-is-not-allowed-in-prolog.html

总之,一些XML文件包含在前面(在<?xml ...?>之前)的三字节模式(0xEF 0xBB 0xBF),即UTF-8字节顺序标记。 java的默认XML解析器不能处理这种情况。

的快速和肮脏的解决方案是在XML文件中的前除去白色空间:

String xml = "<?xml ..."; 
xml = xml.replaceFirst("^([\\W]+)<","<"); 

注意,String.trim()多斯特不够的,因为它只修剪有限的空白字符。

+0

不错,我刚刚被UTF8 Bom烧毁了一系列文件。 – 2013-05-30 15:45:40

+0

更好的解决方案是使用Spring框架提供的'BOMInputStream'。 – Starfish 2017-02-26 19:02:30

+0

太棒了!解决了它。 – 2017-09-14 23:07:06

相关问题