2011-08-04 44 views
0

我想提以下運行在Tomcat中使用Hazelcast,它是拋出NoClassDefFoundException如何在Eclipse

import java.io.IOException; 
import java.io.PrintWriter; 
import java.util.Map; 

import javax.servlet.ServletException; 
import javax.servlet.annotation.WebServlet; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

import com.hazelcast.core.Hazelcast; 

/** 
* Servlet implementation class LoginUser 
*/ 
@WebServlet("/loginUser") 
public class LoginUser extends HttpServlet { 
    private static final long serialVersionUID = 1L; 

    /** 
    * @see HttpServlet#HttpServlet() 
    */ 
    public LoginUser() { 
     super(); 
     // TODO Auto-generated constructor stub 
    } 

    /** 
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 
    */ 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     // TODO Auto-generated method stub 
     Map<String,String> map=Hazelcast.getMap("user"); 
     PrintWriter out=response.getWriter(); 
     String user=request.getParameter("user"); 
     String pwd=request.getParameter("pwd"); 
     if(map.containsKey(user)) 
     { 
      if(pwd!=map.get(user)); 
      { 
       out.write("please correct your password"); 
      } 
     } 
     else 
     { 
      out.write("please correct your username"); 
     } 
    } 

    /** 
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 
    */ 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     // TODO Auto-generated method stub 
    } 

} 

堆棧跟蹤:

SEVERE: Servlet.service() for servlet [ifkaar.admin.LoginUser] in context with path [/IfkaarAdmin] threw exception [Servlet execution threw an exception] with root cause 
java.lang.ClassNotFoundException: com.hazelcast.core.Hazelcast 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523) 
    at ifkaar.admin.LoginUser.doGet(LoginUser.java:35) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:662) 
Aug 4, 2011 12:51:46 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [ifkaar.admin.LoginUser] in context with path [/IfkaarAdmin] threw exception [Servlet execution threw an exception] with root cause 
java.lang.NoClassDefFoundError: com/hazelcast/core/Hazelcast 
    at ifkaar.admin.LoginUser.doGet(LoginUser.java:35) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:662) 
+0

順便說一句:你沒有忘記提問。 Hazelcast類在運行時不可用。你把它們放在你的'WEB-INF/lib'中了嗎? – home

+0

好吧,我已經將hazelcast jar放在WEB-INF/lib中,但仍然拋出異常......在我看來,它是eclipse構建路徑的問題。我需要幫助.... –

+0

好吧,感謝它的工作,現在我把jar放入WEB-INF/lib。 –

回答

1

您需要hazelcast庫你的類路徑在運行時。把這個罐子在WEB-INF/lib

0

您可以將hazelcast庫在任何

  1. 在你的戰爭的在運行時類路徑,如WEB-INF/lib目錄explined(如 別人解釋) - 或 -
  2. 在共享的$ CATALINA_HOME/lib區域