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;
}
}