facebook

NoClassDefFoundError: org/hibernate/Session

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #251732 Reply

    Curt King
    Participant

    I’m working through the Hibernate tutorial. I’ve built an Ant build.xml file that runs my application, but I get this error when I run Ant:

    run:
    [java] java.lang.NoClassDefFoundError: org/hibernate/Session
    [java] Exception in thread “main”
    [java] Java Result: 1

    I know that this package exists in the hibernate3.jar file. I’ve added all of the Hibernate jars to my project’s build path and to the classpath in my configuration for build.xml.

    Any ideas why the java executable wouldn’t be finding this package?

    Thanks,
    Curt

    #251742 Reply

    Haris Peco
    Member

    Curt,

    Please, can you send your build.xml and how you call it

    Thanks

    #251744 Reply

    Curt King
    Participant

    Here’s my build.xml file:

    <project name="hibernate-tutorial" default="compile">
    
        <property name="sourcedir" value="${basedir}/src"/>
        <property name="targetdir" value="${basedir}/bin"/>
        <property name="librarydir" value="${basedir}/lib"/>
    
        <path id="libraries">
            <fileset dir="${librarydir}">
                <include name="*.jar"/>
            </fileset>
        </path>
    
        <target name="clean">
            <delete dir="${targetdir}"/>
            <mkdir dir="${targetdir}"/>
        </target>
    
        <target name="compile" depends="clean, copy-resources">
          <javac srcdir="${sourcedir}"
                 destdir="${targetdir}"
                 classpathref="libraries"/>
        </target>
    
        <target name="copy-resources">
            <copy todir="${targetdir}">
                <fileset dir="${sourcedir}">
                    <exclude name="**/*.java"/>
                </fileset>
            </copy>
        </target>
    
        <target name="run" depends="compile">
            <java fork="true" classname="events.EventManager" classpathref="libraries">
                <classpath path="${targetdir}"/>
                <arg value="${action}"/>
            </java>
        </target>
    
    </project>
    

    I’m calling it by right-clicking on it and going to Run As… / Ant Build. I’ve created a configuration for it in the External Tools dialog. I’ve added all of the Hibernate jars to the “Classpath” tab of the Ant Build configuration (hibernate3.jar plus all of the jars from /lib).

    Here’s the output of the build:

    Buildfile: E:\Eclipse Source\HibernateTest\build.xml
    clean:
       [delete] Deleting directory E:\Eclipse Source\HibernateTest\bin
        [mkdir] Created dir: E:\Eclipse Source\HibernateTest\bin
    copy-resources:
         [copy] Copying 3 files to E:\Eclipse Source\HibernateTest\bin
         [copy] Copied 2 empty directories to 1 empty directory under E:\Eclipse Source\HibernateTest\bin
    compile:
        [javac] Compiling 3 source files to E:\Eclipse Source\HibernateTest\bin
    clean:
       [delete] Deleting directory E:\Eclipse Source\HibernateTest\bin
        [mkdir] Created dir: E:\Eclipse Source\HibernateTest\bin
    copy-resources:
         [copy] Copying 3 files to E:\Eclipse Source\HibernateTest\bin
         [copy] Copied 2 empty directories to 1 empty directory under E:\Eclipse Source\HibernateTest\bin
    clean:
       [delete] Deleting directory E:\Eclipse Source\HibernateTest\bin
        [mkdir] Created dir: E:\Eclipse Source\HibernateTest\bin
    copy-resources:
         [copy] Copying 3 files to E:\Eclipse Source\HibernateTest\bin
         [copy] Copied 2 empty directories to 1 empty directory under E:\Eclipse Source\HibernateTest\bin
    compile:
        [javac] Compiling 3 source files to E:\Eclipse Source\HibernateTest\bin
    run:
         [java] java.lang.NoClassDefFoundError: org/hibernate/Session
         [java] Exception in thread "main"
         [java] Java Result: 1
    BUILD SUCCESSFUL
    Total time: 5 seconds
    

    If you need anything else, please let me know!

    Thanks for your help,
    Curt

    #251748 Reply

    Haris Peco
    Member

    Curt,

    You have to have libraries in lib directory – ant engine doesn’t use project classpath

    Best regards

    #251749 Reply

    Curt King
    Participant

    I’ll try that — but I’m curious why adding the libraries to the Ant configuration’s classpath didn’t work.

    Also, if I added the libraries to my project’s build path, aren’t they automatically placed in my /lib directory?

    Thanks for your patience — I’m still trying to figure all of this out!

    Thanks again for your help,
    Curt

    #251750 Reply

    Haris Peco
    Member

    I’ll try that — but I’m curious why adding the libraries to the Ant configuration’s classpath didn’t work.

    ant doesn’t use classpath out of engine, like eclipse

    Also, if I added the libraries to my project’s build path, aren’t they automatically placed in my /lib directory?

    no, libraries can be anywhere

    Thanks again for your help,

    you welcome

    #282647 Reply

    raj82
    Member

    I am having same problem as Curt has. I have included all librarires in lib folder but still doent work.

    Thank you.

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: NoClassDefFoundError: org/hibernate/Session

You must be logged in to post in the forum log in