Four days ago, I started getting this error message every time I tried to connect to my DB:
java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceProvider
I got it after some time that I was working on other parts of my app, not including DB access, so I don't really know what caused this error.
All I've done in the past four days, was to try googling different combinations of the error above...
So after all that googling, I figured out that, although the error makes it look like I have a missing jar, that is not the case. (I have javax.persistence.jar
and javax.persistence-2.1.0-rc1.jar
in my WebContent/WEB-INF/lib
and the Web App Libraries
is included in the build path).
The only other thing I thought of is maybe I have some version contradiction, and that's why javax.persistence.spi.PersistenceProvider
can not be built, but I have no clue on to how to check that.
And there's also the possibility that I'm mistaken and that there's another problem....
I'm adding here my /WebContent/WEB-INF/web.xml
and /src/main/resources/META-INF/persistence.xml
. If there is anything else needed, please let me know and I'll add it.
I've been trying to solve this problem for already 4 days, and I am really fustrated, please help!
web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID"
version="3.1">
<display-name>InaalEchtok</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
persistence.xml
:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="model_persistence_unit">
<description>Persistence unit for the JPA tutorial of the Hibernate Getting Started Guide</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- <class></class> -->
<properties>
<!-- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /> -->
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<!-- <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/fdb" /> -->
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/fdb?createDatabaseIfNotExist=true" />
<property name="javax.persistence.jdbc.user" value="****" />
<property name="javax.persistence.jdbc.password" value="*********" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<!-- <property name="hibernate.hbm2ddl.auto" value="update" /> -->
</properties>
</persistence-unit>
</persistence>
These are my referenced libraries:
and this is my WEB-INF/lib
: