org.xml.sax.SAXParseExceptionpublicId: http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd

删除回忆录丶 提交于 2019-12-06 14:37:37

The root of the problem seems to lie with Oracle and a concern for security, prompting a recent switch to the HTTPS protocol.
XMLMetaDataParser in org.apache.openjpa.lib.meta uses the SaxParser to read xml files in the parseNewResource method, which throws a premature end of file error. The error text is not particularly informative. However, resorting to XML Copy Editor [http://xml-copy-editor.sourceforge.net] to validate the schema reveals the error actually involved:
Fatal Error at line 0, column 0: unsupported protocol in URL. That information ultimately led me to this post, involving OpenEdge, dated 11/6/2018: [https://knowledgebase.progress.com/articles/Article/Unsupported-protocol-in-URL-reading-XML-from-a-URI].
Under Cause, it states, "The URL used before with HTTP is now redirecting to HTTPS."
And under Resolution, "This is a limitation within the Apache Xerces parser that the OpenEdge client is using internally. It only has limited URL support, so the parser is unable to process the URL redirection or an HTTPS URL similar to a webbrowser."
So the significant portion of the xml text identified in the error message as "systemId" is the http protocol statement, which is now redirected to https at Oracle's web site, causing the parsing error. This explains why code that ran just fine one day suddenly stopped working the following morning. Just how many ORM implementations have this limitation should be known fairly quickly.

Problem solved. I replaced
https://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd
with
https://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd
and the program now builds normally.

I have the same problem since today. My quick fix was to change persistance.xml version from 2.1 to 1.0, it worked for me.

quick fix would be to make the URL http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd just return a 404 and no redirect to https. Like adding 127.0.0.1 xmlns.jcp.org to /etc/hosts.

I resolved by changing http to https, so redirection (which is the problem) will not happen.

<? xml version = "1.0" encoding = "UTF-8"?>
<persistence version = "2.1"
xmlns = "https://xmlns.jcp.org/xml/ns/persistence" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi: schemaLocation = "https://xmlns.jcp.org/xml/ns/persistence https://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

Note: I had this problem with java 7 and glassfish 3, with java 8 and glassfish 4 it works.

Fix for now is to modify your persistence.xml with the schema location:

http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd

Complete first line of persistence.xml looks like this:

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd" version="2.1">

More details and cause: The root cause of this issue is because of the multiple redirections from http to https and vice versa. I used curl to get to the final URL:

curl -v  http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd

HTTP/1.1 301 Moved Permanently Location: https://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd

curl -v https://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd

HTTP/1.1 301 Moved Permanently http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd

Use this in all of your persistence.xml. This worked for me.

NOTE: Oracle might change this final URL again. If at all they change the URL and your build fails, you know how to get to the final URL using curl command.

Thanks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!