简体   繁体   English

EJB Web服务ClassNotFoundException

[英]EJB Web Service ClassNotFoundException

Server: JBoss 7.1.1 EJB 3.0 Eclipse Juno 服务器:JBoss 7.1.1 EJB 3.0 Eclipse Juno

I am working through my first webservice project using ejb 3.0 and am running into a problem on my client. 我正在使用ejb 3.0进行第一个Web服务项目,并且在客户端上遇到问题。 For my client, I made up a servlet. 对于我的客户,我组成了一个servlet。 The problem is when I attempt: 问题是当我尝试:

CalculatorOps calculator = (CalculatorOps)context.lookup("java:global/EJBCalculatorWS/CalculatorImp!math.CalculatorOps");

I am getting ClassNotFoundException on the lookup. 我在查找中收到ClassNotFoundException。 I got this jndi from my JBoss server.log 我从我的JBoss server.log获得了这个jndi

[org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-3) JNDI bindings for session bean named CalculatorImp in deployment unit deployment "EJBCalculatorWS.war" are as follows:

java:global/EJBCalculatorWS/CalculatorImp!math.CalculatorOps
java:app/EJBCalculatorWS/CalculatorImp!math.CalculatorOps
java:module/CalculatorImp!math.CalculatorOps

I have 2 web projects, WS and Client, both added to the server and WS is in the build path of Client. 我有2个Web项目WS和Client,都已添加到服务器,并且WS在Client的构建路径中。

-------------CODE------------ - - - - - - -码 - - - - - -

Interface 接口

package math;

@Local
public interface CalculatorOps {
    public int add(int a, int b);
    public int subtract(int a, int b);
}

Class

package math;

@Stateless(mappedName="TheCalc")
@WebService
public class CalculatorImp implements CalculatorOps{

    @Override
    public int add(int a, int b) {
        return a+b;
    }

    @Override
    public int subtract(int a, int b) {
        return a-b;
    }
}

Servlet Servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

CalculatorOps calculator = (CalculatorOps)context.lookup("java:global/EJBCalculatorWS/CalculatorImp!math.CalculatorOps");

}

Fixed: I ended up fixing this problem by placing the client and the ejb packages together in one project, then using the new jndi. 已修复:我最终通过将客户端和ejb软件包放到一个项目中,然后使用新的jndi来解决了这个问题。 I would still like to know tho why across multiple projects, I cant add to build path and then use the jndi to reference the ejbs without a ClassNotFoundException thrown. 我仍然想知道为什么在多个项目中不能添加构建路径,然后使用jndi引用ejb而不抛出ClassNotFoundException。

If you are using eclipse, you need to add the EJB project to the deployment assembly of your web project to get it working, Build path will only exist for compilation but you get the error during run time if I am right. 如果您使用的是eclipse,则需要将EJB项目添加到Web项目的部署程序集中才能使其正常工作。构建路径仅存在于编译过程中,但如果运行正确,则会在运行时出现错误。

RightClick on your web project->Properties->Deployment Assembly->Add 右键单击您的Web项目->属性->部署程序集->添加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM