1

I'm having a problem with WebSphere Application Server 7. I have 2 applications installed on WAS A & B. B wants to use a local EJB interface of A's.

The module that contains the local EJB interface is part of A's EAR.

What I tried doing was including a reference to the module in my deployment of B. The problem I found was that, while looking up the interface:

InitialContext ic = new InitialContext();
//succeeds
Object obj = ic.lookup("ejblocal:sample.MyEJBLocal");
//fails with ClassCastException
MyEJBLocal localBean = (MyEJBLocal) obj;

The program crashes because the Interface has random letters prefixed to the name of the class, e.g.

Cannot cast type SL07SMyEJBLocal to MyEJBLocal these types are incompatible.

I tried playing around with WAS & I was able to get the cast to succeed by changing the class loader settings for the server from multiple to single.

Q - I don't really like the idea of having one class loader for all the applications on my server - is there another way to get the EJB local interface to be shared across application A & B?

1 Answers1

1

See the "Local client views" section of the EJB modules module of the InfoCenter (I've linked to the 8.5 InfoCenter, but the advice applies to all versions). Basically, in order to share a local interface, you must ensure that both applications have a view of the same class. The most common approach is to use a server-associated shared library. Note carefully the other caveats of sharing a local EJB across applications.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90
  • I did as you suggested & created a shared library. I made the changes to both EAR projects deployment descriptors in the shared library section. I also put a reference in WAS for the jar containing the interface, into the classpath field of the shared library. I then added this to the classloader shared library references.However when I lookup the interface I still get a ClassCastException – user1585676 Aug 09 '12 at 12:06
  • Are you using "parent last" class loading? Is the shared library associated with a server class loader (per the InfoCenter doc)? What do ejb.getClass().getClassLoader() and MyEJBLocal.getClassLoader() say? – Brett Kail Aug 09 '12 at 12:23
  • Maybe you forgot to remove the client-view class files from the EARs? If the client-view class files are located inside the EAR, they will be loaded from there, even if you have them in the shared library. – Isaac Sep 11 '12 at 08:15
  • @Isacc That will only happen if OP is using "parent last". Otherwise, it should be loaded from the configured server class loader. – Brett Kail Sep 11 '12 at 12:39