Hiển thị kết quả từ 1 đến 6 / 6
  1. #1
    Tham gia
    10-05-2009
    Bài viết
    353
    Like
    23
    Thanked 24 Times in 24 Posts

    [ Help ] java.lang.NoClassDefFoundError: Could not initialize class model.lib.HibernateUtil

    Chào ac!
    E viết 1 project trên netbeans, thực hiện chạy ở localhost thì chạy bình thường, nhưng khi up lên host thay lại username và password để kết nối cơ sở dữ liệu thì nó báo lỗi. e viết lại 1 cái nhỏ để test thì nó báo:
    java.lang.NoClassDefFoundError: Could not initialize class model.lib.HibernateUtil
    ---------
    toàn bộ lỗi là :
    PHP Code:
    HTTP Status 500 -

    type Exception report

    message

    description The server encountered an internal error 
    () that prevented it from fulfilling this request.

    exception

    org
    .apache.jasper.JasperExceptionAn exception occurred processing JSP page /index.jsp at line 23

    20
    :         <h2>test<br /></h2>
    21:         <jsp:useBean id="test" class="controller.TestController" scope="page">
    22:             <%
    23:                List<TestlistTest test.getTests();
    24:                pageContext.setAttribute("listTest"listTest);
    25:             %>
    26:             <c:forEach items="${listTest}var="item">


    Stacktrace:
        
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
        
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
        
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
        
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        
    java.lang.reflect.Method.invoke(Method.java:597)
        
    org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
        
    java.security.AccessController.doPrivileged(Native Method)
        
    javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
        
    org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
        
    org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

    root cause

    javax
    .servlet.ServletExceptionjava.lang.NoClassDefFoundErrorCould not initialize class model.lib.HibernateUtil
        org
    .apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
        
    org.apache.jasper.runtime.PageContextImpl.access$1100(PageContextImpl.java:71)
        
    org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:766)
        
    java.security.AccessController.doPrivileged(Native Method)
        
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:764)
        
    org.apache.jsp.index_jsp._jspService(index_jsp.java:104)
        
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
        
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
        
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        
    java.lang.reflect.Method.invoke(Method.java:597)
        
    org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
        
    java.security.AccessController.doPrivileged(Native Method)
        
    javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
        
    org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
        
    org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

    root cause

    java
    .lang.NoClassDefFoundErrorCould not initialize class model.lib.HibernateUtil
        controller
    .TestController.getTests(TestController.java:41)
        
    org.apache.jsp.index_jsp._jspService(index_jsp.java:85)
        
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
        
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
        
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        
    java.lang.reflect.Method.invoke(Method.java:597)
        
    org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
        
    java.security.AccessController.doPrivileged(Native Method)
        
    javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
        
    org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
        
    org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)

    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs
    ---------

    file Hibernate.java nội dung là:
    PHP Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */

    package model.lib;


    import org.hibernate.cfg.Configuration;
    import org.hibernate.SessionFactory;

    /**
     * Hibernate Utility class with a convenient method to get Session Factory object.
     *
     * @author LE VAN ANH
     */
    public class HibernateUtil {
        private static final 
    SessionFactory sessionFactory;

        static {
            try {
                
    // Create the SessionFactory from standard (hibernate.cfg.xml) 
                // config file.
                
    sessionFactory = new Configuration().configure().buildSessionFactory();
            } catch (
    Throwable ex) {
                
    // Log the exception. 
                
    System.err.println("Initial SessionFactory creation failed." ex);
                throw new 
    ExceptionInInitializerError(ex);
            }
        }

        public static 
    SessionFactory getSessionFactory() {
            return 
    sessionFactory;
        }

    file hibernate.cfg.xml

    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3307/vnseach</property>
        <property name="hibernate.connection.username">test</property>
        <property name="hibernate.connection.password">alofun260490</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <mapping resource="model/Test.hbm.xml"/>
      </session-factory>
    </hibernate-configuration>
    Quote Quote

  2. #2
    Tham gia
    16-12-2010
    Bài viết
    14
    Like
    1
    Thanked 0 Times in 0 Posts
    Khả năng cao là cậu chưa up class lên classes của server

  3. #3
    Tham gia
    10-05-2009
    Bài viết
    353
    Like
    23
    Thanked 24 Times in 24 Posts
    dạ không! E code với netbeans, khi code chạy được ở localhost ok rồi thì e build thành file war rồi up file đó.
    Bây giờ cái project của e chỉ chạy được localhost, hjx!

  4. #4
    Tham gia
    01-06-2007
    Bài viết
    2,148
    Like
    0
    Thanked 6 Times in 5 Posts
    Quote Được gửi bởi anh2604 View Post
    dạ không! E code với netbeans, khi code chạy được ở localhost ok rồi thì e build thành file war rồi up file đó.
    Bây giờ cái project của e chỉ chạy được localhost, hjx!
    bạn xài server gì vậy? có thể server không tìm thấy file đó. bạn thử mấy cách sau xem:
    1. Xóa thư mục dist và build của netbeans vì nó có thể build lỗi.
    2. Check classpath xem có ổn ko
    3. Sau đó clean & build lại
    4. Deploy lại
    5. Nếu vẫn ko thấy thì chép tay tập tin đó lên vào thư mục cụ thể nào đó tùy vào server bạn dùng (đọc tài liệu về server đó nhé, vì mỗi server có cách tổ chức file khác nhau)

  5. #5
    Tham gia
    10-05-2009
    Bài viết
    353
    Like
    23
    Thanked 24 Times in 24 Posts
    E dùng host free http://eatj.com, server này dùng Tomcat ạ. e up file vào thư mục ../webapps/, trong file hibernate.cfg.xml username và pass để trùng với username, pass đăng nhập trang này.
    e thử dùng trang free này để thử project, trang này suốt ngày phải restart nên nếu project chạy ổn thì e mới up vào host e mua.

  6. #6
    Tham gia
    01-06-2007
    Bài viết
    2,148
    Like
    0
    Thanked 6 Times in 5 Posts
    đóng nó thằng war, dùng giao diện của tomcat để úp hay là bạn dùng 1 ftp client để làm chuyện này? Rồi xem bạn có quyền đọc file trên cái tomcat đó không nữa. Ví dụ: nếu nó dùng tomcat và share cho mọi người, nó chỉ cho bạn quyền truy xuất ở một thư mục nhất định mà thôi, trong khi đó thì những file jar sẽ bị nhét vô 1 chỗ khác và bạn không có quyền. Do đó, khi project của bạn chạy, và cần load 1 jar ở chỗ bị cấm, nó sẽ không thấy và báo classnotfound.

    Bạn có thể thử làm cái này trên môi trường linux tại nhà, tạo một file jar có package là a.b.c.d, sau đó chỉ cần cấm quyền truy xuất thư mục d thôi thì cũng bị báo lỗi này đó. Trên Windows thì ko phức tạp như vậy.

Bookmarks

Quy định

  • Bạn không thể tạo chủ đề mới
  • Bạn không thể trả lời bài viết
  • Bạn không thể gửi file đính kèm
  • Bạn không thể sửa bài viết của mình
  •