没有ClassDefFound将maven项目作为依赖项添加到java中的非maven时出错

时间:2012-12-05 20:48:15

标签: java web-services maven-2 axis2 noclassdeffounderror

我正在尝试开发Axis2网络服务。我创建了一个动态Web项目来从WSDL生成我的Web服务类。我在Skelton中实现了我的逻辑,其中包含查询数据库的代码。

所有这些数据库访问逻辑都在另一个Maven构建的Project中。我将这个Maven构建项目作为我的webservice项目BuildPath中的依赖项添加到我的webservice项目中,该项目不是maven构建的。

当我运行此网络服务并点击Soap UI的服务时,我收到No ClassDef Found Error,如下所示。

[ERROR] com/sample/test/common/dao/PersonDAO
java.lang.NoClassDefFoundError: com/sample/test/common/dao/PersonDAO
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    at org.apache.axis2.util.Utils$8.run(Utils.java:768)
    at org.apache.axis2.java.security.AccessController.doPrivileged(AccessController.java:132)
    at org.apache.axis2.util.Utils.createServiceObject(Utils.java:765)
    at org.apache.axis2.receivers.AbstractMessageReceiver.makeNewServiceObject(AbstractMessageReceiver.java:245)
    at org.apache.axis2.receivers.AbstractMessageReceiver.getTheImplementationObject(AbstractMessageReceiver.java:282)
    at rg.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

我的网络服务代码

     public class EnrollmentServiceSkeleton implements EnrollmentServiceSkeletonInterface{

            @Autowired
            PersonDAO personDao;   // Getters and Setters.

        public EnrollmentServiceRespMessage enrollmentServiceProfile (EnrollmentServiceReqMessage enrollmentService) {

// My WebService Logic
}

将maven项目作为非maven项目的构建路径中的另一个非maven依赖项的正确方法是否正确?

1 个答案:

答案 0 :(得分:1)

Maven通过构建项目但不在包中构建其依赖项来工作。因此,使用该库的项目可以选择覆盖或排除maven依赖。

当包含在非maven项目中时,您需要构建它,包括依赖项。

请参阅How can I create an executable JAR with dependencies using Maven?,详细了解如何操作。