我正在使用glassfish服务器,以下错误不断出现:
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
答案 0 :(得分:4)
检查此链接
简而言之,某些XML文件在前面(<?xml ...?>
之前)包含三字节模式(0xEF 0xBB 0xBF),这是UTF-8字节顺序标记。 java的默认XML解析器无法处理这种情况。
快速而肮脏的解决方案是删除XML文件前面的空白区域:
String xml = "<?xml ...";
xml = xml.replaceFirst("^([\\W]+)<","<");
请注意String.trim()dost不够,因为它只修剪有限的空白字符。