在使用hibernate时出现java.lang.NoClassDefFoundError: net/sf/hibernate/SessionFactory错误
各位兄弟,我在使用hibernate时出现java.lang.NoClassDefFoundError: net/sf/hibernate/SessionFactory错误,请问该怎么解决。
以下是我的文件,主要是在执行execute方法时出现了这个错误。
package addressbook.actions;
import java.io.IOException;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import addressbook.forms.InsertForm;
import addressbook.bookinfo.*;
import addressbook.Constants;
import addressbook.hibernate.*;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
/**
* <strong>InsertAction</strong> inserts a new record into the database.
*/
public final class InsertAction extends HibernateBase {
public InsertAction()throws Exception
{
super();
}
private Log log =
LogFactory.getLog(this.getClass().getName());
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
Locale locale = getLocale(request);
MessageResources messages = getResources(request);
String name=null;
String phone=null;
String address=null;
ActionMessages errors = new ActionMessages();
name = ((InsertForm) form).getName();
phone=((InsertForm)form).getPhone();
address=((InsertForm)form).getAddress();
try
{
AddressbookTable bean=new AddressbookTable();
bean.setAddress(address);
bean.setPhone(phone);
bean.setName(name);
beginTransaction();
session.save(bean);
endTransaction(true);
}
catch(Exception ex)
{
ex.printStackTrace(System.out);
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("error.insert.failed"));
}
if (!errors.isEmpty()) {
saveMessages(request, errors);
return (new ActionForward(mapping.getInput()));
}
// If we had no errors, then add a confirmation message
ActionMessages actionMessages = new ActionMessages();
actionMessages.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("record.inserted"));
saveMessages(request,actionMessages);
return (mapping.findForward(Constants.FORWARD_CONFIRMATION));
}
}