简体   繁体   中英

EJB Web Service ClassNotFoundException

Server: 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. For my client, I made up a 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. I got this jndi from my JBoss server.log

[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.

-------------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

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. 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.

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.

RightClick on your web project->Properties->Deployment Assembly->Add

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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