1

I was working on a spring mvc maven project and in initial stage I can across this error. in my servlet-context.xml, I am trying to generate "HibernateTransactionManager" bean which throws me this errr :

error: "Build path is incomplete. Cannot find class file for org/hibernate/HibernateException"

as this being a maven project I have added the following dependency in pom.xml

<!--  Dependency added for spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>               


    <!-- Dependency added for Spring Security -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>

    <!-- Dependency added for AOP -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
    </dependency>

    <!-- Dependency for Hibernate -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework-version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${org.hibernate-version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.2.0.Final</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${com.mysql-version}</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>20030825.184428</version>
    </dependency>
    <dependency>
        <groupId>commons-pool</groupId>
        <artifactId>commons-pool</artifactId>
        <version>20030825.183949</version>
    </dependency>
    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>

    <!-- Dependency for Http Client -->
    <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.1.1</version>
    </dependency>
    <dependency>
        <groupId>jdom</groupId>
        <artifactId>jdom</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
    <groupId>rome</groupId>
    <artifactId>rome</artifactId>
    <version>0.5</version>
    </dependency>

I can even locate all my classes in my Maven dependency tree.

I have also tried to externally add a new .jar for spring-orm but that didnt work as well. I have tried to clean build and re-compile several times but that didn't work out.

I would really appreciate any of your inputs.

user1324493
  • 15
  • 2
  • 5
  • Could it be related to [this SO question](http://stackoverflow.com/questions/4262186/missing-maven-dependencies-in-eclipse-project)? – Raghuram Apr 16 '12 at 07:57

2 Answers2

1

This is my first SO answer, so please bear with me. The error generated is “Cannot find class file for org/hibernate/HibernateException”. The POM you have provided lists all the dependencies your project and including a reference to the hibernate-validator jar.

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>

If you extract this jar file and search its contents, no class file named HibernateException can be found. This is the root cause of the error and you a repository that contain the HibernateException class file.

As you are using maven, you can see all the repositories related to Hibernate here http://mvnrepository.com/artifact/org.hibernate

I’ve selected the hibernate-core-4.2.0.Final as core would suggest it has most of the main class files hibernate requires. Downloading and extracting the jar shows that the HibernateException class file exists here.

Therefore, if you update your POM.xml with the following entry

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.0.Final</version>
</dependency>

Now you have to make Maven download the repository to your local machine if it doesn’t exist and use it for your project. If you are running the project from Elcipse, do this by right-clicking the project->Run As-> Maven Clean.

Hope this helps.

bazza90
  • 62
  • 6
0

if you are sure that maven has downloaded the hibernate jar's and are available in/to the jar/war file generated from the build then the issue could be as follows.

sometimes Maven fails to download the complete JAR file from the server, a class not found exception can occur in those cases as well.

to fix this goto .m2 folder in your home directory, delete the hibernate jar's and make a clean install. this will download the new set of files and things should start to work.

you can check if the files were downloaded correctly by opening them as a zip file jar tf jar-file.jar

Anantha Sharma
  • 9,920
  • 4
  • 33
  • 35