Skip to content

TOMEEE – Can’t lookup ejb

I have implemented a basic EJB Object in my code. Then I created a jar for this ejb. The jar file contains:

  1. package containing the ejb classes (home interface/remote bean interface/bean implementaion)
  2. META-INF folder containing the ejb-jar.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "">

Then I deployed the EJB by placing the jar in webapps folder and from the server logs it seems to have been deployed successfully. But when I try to reference the ejb from my code I get error. Code:

Properties p = new Properties();
                   p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
                   InitialContext context = new InitialContext(p);
                   ejbHome = (EJBHome) context.lookup("java:global/NewTransactionEjb/NewTransactionEjb");

I have used “java:global/NewTransactionEjb/NewTransactionEjb” because upon ejb deployment I see this line in the server logs:

03-Sep-2021 17:31:23.628 INFO [Catalina-utility-1] org.apache.openejb.assembler.classic.JndiBuilder.bind Jndi(name=global/NewTransactionEjb/NewTransactionEjb!gr.cosmote.mdb.NewTransactionEjb.NewTransactionEjbHome) 
--> Ejb(deployment-id=NewTransactionEjb)

In the execution it seems the the above code is working and it retrieves the EJBHome, but when I try to cast it to my own home interface class it fails with the following error:

java.lang.ClassCastException: com.sun.proxy.$Proxy362 cannot be cast to

What am I doing wrong?


I have finally found the solution to this issue. To be precise the actual problem has nothing to do with the exception which is just confusing. So I will mention my problem anyway, in case someone faces the same issue.

My problem was that 2 of the EJB classes (home interface and remote bean interface) were also in TOMEE /lib directory except for the EJB deployable jar file which was placed in /webapps directory. So I removed them from the jar file (now it contains only the bean implementaion class), deployed it and everything is working fine.