1

When I run my project on IntelliJ, it gives me a java.io.IOException: org.xml.sax.SAXParseException error.

I can't find the problem. Can someone help me with this error?

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
</web-app>

Persistence.xml

<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://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="aquadinePU" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/aquadine?autoReconnect=true&amp;useSSL=false&amp;allowPublicKeyRetrieval=true" />
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="ruta" />
            <property name="hibernate.show_sql" value="true"/>
        </properties>
    </persistence-unit>

</persistence>

The error for web.xml is as follows:

java.io.IOException: org.xml.sax.SAXParseExceptionpublicId: http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd; lineNumber: 1; columnNumber: 1; Deployment descriptor file WEB-INF/web.xml in archive [aquadine-jee].  Premature end of file.

The error for persistence.xml is as follows:

java.io.IOException: org.xml.sax.SAXParseExceptionpublicId: http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd; lineNumber: 1; columnNumber: 1; Deployment descriptor file META-INF/persistence.xml in archive [classes].  Premature end of file.
Ömer Uyar
  • 21
  • 1
  • 6
  • This post describes the problem [SAXParseException](https://stackoverflow.com/questions/56728487/org-xml-sax-saxparseexceptionpublicid-http-xmlns-jcp-org-xml-ns-persistence-p/56741356#56741356) – Robert Peake Jun 25 '19 at 05:22

2 Answers2

3

We also started getting this Error since a few days. The uri:

 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd 

returns a status code 301 which the SAX Parser cant handle.

Our hotfix was to change the schema location in the web.xml to the new file:

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_1.xsd
  • Thank you very much, I got the same problem for the persistence and I fixed it with your hotfix. – Ömer Uyar Jun 24 '19 at 12:52
  • 1
    I urge anyone encountering this issue to file a bug report with their ORM vendor. This solution worked for me and should continue to work unless Oracle moves the file again. OpenJPA has already addressed the problem [OpenJPA-2791](https://issues.apache.org/jira/browse/OPENJPA-2791?filter=-2). – Robert Peake Jun 26 '19 at 15:46
0

I changed the validation urls to https so the redirect, 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.

Another thing, in glassfish 3, I needed to disable the weld xml validations, add the parameter in the glassfish

-Dorg.jboss.weld.xml.disableValidating = true
  • 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. – Robert Peake Jun 25 '19 at 17:55