2011-10-06 62 views
15

我已经用jsf在jsp文件中创建了一个注册表单,我尝试将它与一个web服务连接,以便通过这些元素一个数据库。java.lang.NoClassDefFoundError:org/apache/commons/discovery/tools/DiscoverSingleton

当我按下提交按钮时,我得到一个错误。我不认为问题涉及连接代码,但我不确定。

有人能告诉我一些可能以某种方式帮助我的东西吗?

错误:

javax.servlet.ServletException: #{formabean.submitdetails}: java.lang.NoClassDefFoundError: org/apache/commons/discovery/tools/DiscoverSingleton 
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:256) 
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390) 

我的表单JSP:

<%@page contentType="text/html" pageEncoding="UTF-8"%> 

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> 
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd"> 

<f:view> 
    <html> 
     <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
      <title>Form</title> 
     </head> 
     <body> 
      <div align="right" > 
       <p> 
        <br>............. 
<h:commandButton value="submit" type="submit" 
           action="#{formabean.submitdetails}" /> 


      </h:form> 

     </body> 
    </html> 
</f:view> 

我Bean类 “formavar”:

package org.forma; 

import org.imigrant.Migration.MigrationResult; 
import org.imigrant.Migration.MigrationWS_PortType; 
import org.imigrant.Migration.MigrationWS_Service; 
import org.imigrant.Migration.MigrationWS_ServiceLocator; 

/** libraries for Web Service*/ 
/** 
* 
* @author USER 
*/ 
public class formavar { 

    private String name; 
    private String lastname;..... 
public String getName() { 
     return name; 
    } 

    /** 
    * @param name the name to set 
    */ 
    public void setName(String name) { 
     this.name = name; 
    } 

    /** 
    * @return the surname 
    */ 
    public String getLastname() { 
     return lastname; 
    } 

    /** 
    * @param surname the surname to set 
    */ 
    public void setLastname(String lastname) { 
     this.lastname = lastname; 
    }...... 
public String submitdetails() { 
     String migrationURL = "http://localhost:8080/mule-tomcat/ESB/Migration?wsdl"; 
     MigrationResult registrationResult = new MigrationResult(); 

     try { 

      MigrationWS_Service service = new MigrationWS_ServiceLocator(migrationURL); 
      MigrationWS_PortType port = service.getMigrationImplPort(); 

      registrationResult = port.registerDoc(
       null, 
       this.granting, 
       this.expire_date, 
     this.name, 
     this.lastname,............. 

        ); 


      return "OK"; 

     } catch (Exception ex) { 


      return "ERROR "+ex.getMessage(); 
     } 


     //return "OK"; 
    } 
} 

和配置XML:

<managed-bean> 
     <managed-bean-name>formabean</managed-bean-name> 
     <managed-bean-class>org.forma.formavar</managed-bean-class> 
     <managed-bean-scope>request</managed-bean-scope> 
    </managed-bean> 
+1

的BalusC答案是正确的。请注意,您似乎在部署之后而不是在编译期间收到错误。对我而言,这表明您拥有apache commons发现jar,但不会将其部署到您的应用程序中。如果你正在构造一个war文件,你可以通过将它放在/ WEB-INF/lib目录中(在war中),将发现jar放到你的运行时类路径中。 – DwB

回答

17

java.lang.NoClassDefFoundError: org/apache/commons/discovery/tools/DiscoverSingleton

这只是表示在webapp的运行时类路径中缺少提到的类(或包含类的JAR文件)。

作为包名提示,该类是Apache Commons Discovery的一部分,可在http://commons.apache.org/discovery下载。如果您只是将其JAR文件放在您的webapp的/WEB-INF/lib(由webapp的运行时类路径覆盖)中,那么此错误应该消失。

请注意,这个问题有没有什么与JSF/JSP,更不用说Java EE了。这只是基本的Java。这个例外的根本原因也暗示了这一点;它的包装是java.lang

11

在执行测试时,项目类路径中缺少指定的类。

的解决方案是以下依赖添加到您的POM:

<dependency> 
    <groupId>commons-discovery</groupId> 
    <artifactId>commons-discovery</artifactId> 
    <version>0.5</version> 
    <scope>test</scope> 
</dependency> 
+0

添加在您的POM: \t \t 公共发现 \t 公共发现 \t \t 0.5 \t \t 测试 Fadid

+0

你解决我的问题!谢谢! – hbobenicio