1

I'm working on a project and it kept generating error when runing the project.

I need help to solve this issue please, thank you in advance.

UPDATE -------------------------------

I'm still struggling with this issue, in the beginning when i was trying to test the methods everythings works fine, all the insert, update, delete... but when i added Servlet I got these errors.


This is my first time using Maven and Hibernate and it's giving tons of errors such as

java.lang.NoClassDefFoundError: org/hibernate/query/Query at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1407) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1215)

I have tried this solution it works (the servlet works too) for a little while then back to the same problem again.

pom.xml :

        <?xml version="1.0" encoding="UTF-8"?>
        
        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
        
          <groupId>org.eclipse</groupId>
          <artifactId>GestionDesAchats1</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <packaging>war</packaging>
        
          <name>SchoolProject Maven Webapp</name>
          <!-- FIXME change it to the project's website -->
          <url>http://www.example.com</url>
        
          <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.7</maven.compiler.source>
            <maven.compiler.target>1.7</maven.compiler.target>
          </properties>
        
          <dependencies>
            <dependency>
              <groupId>junit</groupId>
              <artifactId>junit</artifactId>
              <version>4.11</version>
              <scope>test</scope>
            </dependency>
            
            <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
            </dependency>
            
            
            <dependency>
                <groupId>commons-digester</groupId>
                <artifactId>commons-digester</artifactId>
                <version>2.1</version>
            </dependency>
            
            <dependency>
              <groupId>org.hibernate</groupId>
              <artifactId>hibernate-core</artifactId>
              <version>5.6.0.Final</version>
            </dependency>
            
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>4.0.0</version>
                <scope>provided</scope>
            </dependency>
            
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>javax.servlet.jsp-api</artifactId>
                <version>2.3.2-b02</version>
                <scope>provided</scope>
            </dependency>
            
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
            </dependency>
            
            <dependency>
              <groupId>mysql</groupId>
              <artifactId>mysql-connector-java</artifactId>
              <version>8.0.27</version>
            </dependency>
            
          </dependencies>
        
          <build>
            <finalName>SchoolProject </finalName>
            <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
              <plugins>
                <plugin>
                  <artifactId>maven-clean-plugin</artifactId>
                  <version>3.1.0</version>
                </plugin>
                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
                <plugin>
                  <artifactId>maven-resources-plugin</artifactId>
                  <version>3.0.2</version>
                </plugin>
                <plugin>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>3.8.0</version>
                </plugin>
                <plugin>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <version>2.22.1</version>
                </plugin>
                <plugin>
                  <artifactId>maven-war-plugin</artifactId>
                  <version>3.2.2</version>
                </plugin>
                <plugin>
                  <artifactId>maven-install-plugin</artifactId>
                  <version>2.5.2</version>
                </plugin>
                <plugin>
                  <artifactId>maven-deploy-plugin</artifactId>
                  <version>2.8.2</version>
                </plugin>
              </plugins>
            </pluginManagement>
          </build>
        </project>

jars :

enter image description here

Error

enter image description here


update2 I couldn't fix the problem so I switched to Dynamic web Project, and now everything works fine, i didn't even had to change a piece of code or add other jars.

1
  • Can you share your java code? Commented Dec 30, 2021 at 1:53

1 Answer 1

1

Try running an mvn dependency:tree to see what your classpath looks like.

There is a compatibility matrix between hibernate, REST and other components. That means you have to use the right versions together. It's often non-trivial to figure out which ones to combine, but mvn dependency:tree -Dverbose will give you insight where you overwrite versions. These days, most platforms have a website to generate a compatible pom for you (Quarkus, Spring, etc). But old-school war based deployments typically don't have that yet. Non-war based deployments of Hibernate with Rest look differently: here's an example.

A quick search shows that the class org.hibernate.query.Query existed in hibernate-core 5.2, but not in 5.6, where it got moved to org.hibernate:hibernate-search-orm.

Try adding a dependency on hibernate-search-orm too:

        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-search-orm</artifactId>
          <version>5.6.0.Final</version>
        </dependency>
Sign up to request clarification or add additional context in comments.

4 Comments

I added this this dependency and ran mvn dependency:tree -Dverbose and got this warning [WARNING] The artifact xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2
Unrelated to fix your issue, but a good sign of how hard dependency managment and the compatibility matrix is - and how it's easier to let the upstream platform handle that pain for you, by importing a platform bom to handle the versions for you.
I'm still struggling with this issue, in the beginning when i was trying to test the methods everythings worked fine, all the insert int database, update, delete... but when i added Servlet I got these errors? do you have any idea how to solve it please ?
Is there some light for this question? We're with the same problem. Locally WildFly runs normally. Therefore, running inside Jenkins this trouble ocurrs to this class: Caused by: java.lang.NoClassDefFoundError: org/hibernate/Query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.