简体   繁体   中英

web.xml SAXParseException error when running a project in glassfish server

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM