I'm getting this problem when I try to deploy a war to a Tomcat 7 server:
IllegalArgumentException: Invalid XML in persistence unit from URL [jar:file:/opt/webapps/foo/WEB-INF/lib/bar.jar!/META-INF/persistence.xml]
SAXParseException; cvc-elt.1: Cannot find the declaration of element 'persistence'.
I've read countless similar questions here, but all the problems were caused by wrong namespaces, mismatching versions, missing elements... My persistence.xml file is correct, as far as I can tell:
<?xml version="1.0" encoding="UTF-8"?>
<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="my_pu" transaction-type="RESOURCE_LOCAL">
<class>com.foo.Bar</class>
<class>com.foo.Baz</class>
</persistence-unit>
</persistence>
In fact, the same war works just fine on my PC and on our development environment. It just fails when we promote it to our testing environment. I believe it might be due to xmlns.jcp.org not being reachable from that server, at least I don't get any reply when I try to curl the XSD URL, it just timeouts. Also, it takes the Tomcat around 1 minute to show the error message, which also gives the idea that it's trying to load the remote XSD and getting a timeout.
I've spent the last 5 hours trying to make it take a local XSD file instead, but so far I haven't succeeded. I've tried placing the file...
- Directly in WEB-INF/.
- Inside the jar which contains the persistence.xml, in the same folder (META-INF/).
- Inside the jar, in the WEB-INF/ folder.
And in the persistence.xml:
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
version="2.1">
<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 persistence.xsd"
version="2.1">
<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 ./persistence.xsd"
version="2.1">
<persistence>
<persistence version="2.1">
The only thing I've accomplished is to avoid the 1 minute waiting time, if I remove the schemaLocation. But the problem persists. (no pun intended...)
The persistence.xml file is loaded from an applicationContext.xml, in case it makes any difference:
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
...
</bean>
What else can I try?