-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: ClassNotFoundException: HibernateUtil.java
PostPosted: Sat May 02, 2009 12:59 am 
Newbie

Joined: Sat May 02, 2009 12:23 am
Posts: 1
I am following Hibernate's online tutorial and practices. When I try to compile the HibernateUtil.java in chapter 1, the output claims my class cannot be found. In details, the error output is:

Code:
C:\Users\tyun\Desktop\Hibernate\src\util>dir/w
Volume in drive C is ACER
Volume Serial Number is 303E-BC76

Directory of C:\Users\tyun\Desktop\Hibernate\src\util

[.]                   [..]                  HibernateUtil.class
HibernateUtil.java
               2 File(s)          1,858 bytes
               2 Dir(s)  46,400,139,264 bytes free

C:\Users\tyun\Desktop\Hibernate\src\util>javac -classpath ../../lib/hibernate3.
ar HibernateUtil.java

C:\Users\tyun\Desktop\Hibernate\src\util>java -classpath ../..lib/hibernate3.ja
HibernateUtil
Exception in thread "main" java.lang.NoClassDefFoundError: HibernateUtil
Caused by: java.lang.ClassNotFoundException: HibernateUtil
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: HibernateUtil.  Program will exit.


My directory structure is:

Code:
+lib
  hsqldb.jar
  hibernate3.jar
+src
  +events
    Event.java
    Event.hbm.xml
  +util
    HibernateUtil.java
  hibernate.cfg.xml
+data
build.xml


and my HibernateUtil.java is:

Code:
package util;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.