cancel
Showing results for 
Search instead for 
Did you mean: 

Can not lookup EJB from another EAR file, the ClassCastException returned

Former Member
0 Kudos

Hi,

I try to call EJB module in A.ear from Servlet in another EAR file(B.ear) the ClassCastException returned on the context.lookup() code . So when i create a Dynamic Web Project(With the same code as Servlet in B.ear) and pack it in A.ear(The same EAR file with EJB module), it work fine. I have no idea. Could you please suggest me.

The ClassCastException : incompatible with interface ..... return on

HelloManBeanLocalHome home=(HelloManBeanLocalHome) ctx.lookup("localejbs/sap.com/HelloMan_EAR/HelloManBean");

The entire code is below :

		try {			
			InitialContext ctx=new InitialContext();
			HelloManBeanLocalHome home=(HelloManBeanLocalHome) ctx.lookup("localejbs/sap.com/HelloMan_EAR/HelloManBean");
			HelloManBeanLocal remote=home.create();
			lookupText=remote.helloMan("Test");

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace(out);
		}

Many Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Thongie,

Could you please bulid and redploy the two ear files. First bulid and deploy the A.ear file.

Then add the reference of A.ear to your B.ear, build the B.ear and deploy it and check.

If this doesn't work please look at this links

http://wiki.sdn.sap.com/wiki/display/XI/SapNetweaverProcessIntegration.CallEjb3.0methodfromJavaclassmappingPI7.1

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/0736159e-0301-0010-9ea4-c63d83d07...

Hope this helps you.

Regards,

Saleem Mohammad.

Former Member
0 Kudos

Hi Saleem Mohammad.

Thank a lot for your post. I got this idea from your link. The below code work fine.

		try {			
			InitialContext ctx=new InitialContext();
						
			Object obj= ctx.lookup("localejbs/sap.com/HelloMan_EAR/HelloManBean");
			 ClassLoader homeCl = obj.getClass().getClassLoader();
			 
			 Class<?> localHome = homeCl.loadClass(HelloManBeanLocalHome.class.getCanonicalName());
			 java.lang.reflect.Method method = localHome.getMethod("create");			
			 Object homeObj = (Object)method.invoke(obj); 

			 ClassLoader localCl=homeObj.getClass().getClassLoader();
			 Class<?> local = localCl.loadClass(HelloManBeanLocal.class.getCanonicalName());
			 Class  args[] = {String.class};
			 java.lang.reflect.Method localMethod=local.getMethod("helloMan",args);			 
			 Object params[]={"Thongie"};
			 Object localObj = (Object)localMethod.invoke(homeObj,params);
			 
			 lookupText=(String)localObj;			
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace(out);
		}

Answers (0)