set HIBERNATE_LIB=D:/work /WebRoot/WEB-INF/lib set HIBERNATE_CLASSES=D:/work /WebRoot/WEB-INF/classes 在set CLASSPATH 之后加入: %HIBERNATE_LIB%/cglib-full-2.0.2.jar;%HIBERNATE_LIB%/commons-beanutils.jar;%HIBERNATE_LIB%/commons-collections.jar;%HIBERNATE_LIB%/commons-lang.jar;%HIBERNATE_LIB%/commons-logging.jar;%HIBERNATE_LIB%/dom4j-1.4.jar;%HIBERNATE_LIB%/hibernate2.jar;%HIBERNATE_LIB%/jcs.jar;%HIBERNATE_LIB%/odmg.jar;%HIBERNATE_CLASSES%
4) 打开weblogic控制台,在左侧的树中点击StartUp & Shutdown,然后在右边的主页面中点击“Configure a new Startup Class...”配置一个自动运行类,在Name框里面随便填写,在ClassName里面填写你编写的StartUp类:com.starup. HibernateInitStartUp,然后点击apply,在接下来的Target选项中选择myserver(根据你的情况而定),点击apply按钮。
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class HibernateInitStartUp implements ServletContextListener { public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
public void contextInitialized(ServletContextEvent servletContextEvent) {
try { Configuration conf = new Configuration().configure(); SessionFactory sf = conf.buildSessionFactory(); } catch (Exception e) { e.PRintStackTrace(); } } }