Search code examples
jakarta-eedependency-injectionjndisession-bean

Java-EE6: What's the proper way to call a stateless bean from a sub-project?


My Enterprise Application (E-APP) features an additional class library project (CLP) that acts as interface lib between my E-APP and my stand-alone Java SE fat-client (E-APP references the built jar-file of CLP). Now I need to call methods on session beans residing in my E-APP, but since only E-APP references CLP, I don't have access to those bean classes. How would I solve this issue ? Doing JNDI remote calls, altough the CLP classes reside as jar-file on the application server ? Or is there a way to use dependency injection in this case ?


Solution

  • There's no way using dependency injection for remote clients. Using JNDI to lookup a reference to the bean solved the issue. Here's an example:

    PersonFacadeRemote personFacade = (PersonFacadeRemote)ctx.lookup("java:global/SuiteEE/SuiteEE-ejb/PersonFacade!ch.suite.control.PersonFacadeRemote");
    

    Where PersonFacadeRemote is an @Remote annotated interface in the project that is referenced by the server as well the client component. PersonFacade is on the server.