5 Replies Latest reply on Sep 22, 2014 8:42 PM by James Livingston

    How to share a @Singleton EJB between differents applications?

    Juan Martin Runge Newbie

      Hi,

      What Im trying to accomplish is to deploy an EJB and to use it from different other applications that may reside in the same server.  Perhaps the way to go is to write a module, but I dont know how...

       

      Let me give an example of what Im trying to do:

       

      An EJB (or plain JAR) Project with this class inside only:

      @Singleton

      @LocalBean

      public class SmsService {

           @PostConstruct

           public void init() {

                System.out.println("Hello, I'm an EJB");

           }

       

           public void greetMe(String name) {

                System.out.println("Hi " + name);

           }

      }

       

      I want to deploy this project on its own to wildfly.

       

      Then I want to have another project, lets say a WAR, for example, with this class:

      @Stateless

      @LocalBean

      public class SmsClient {

           @Resource

           private SmsService service;

       

           @PostConstruct

           public void init() {

                service.greetMe("pepe");

           }

      }

       

      And I want to have my first project referenced this way in my pom.xml (I forgot to say I was using Maven and Netbeans 8.0):

      <dependency>

           <groupId>sms</groupId>

           <artifactId>SmsService</artifactId>

           <version>0.0.1</version>

           <scope>provided</scope>

      </dependency>

       

      I did accomplish something similar, but using JNDI and I didnt manage to make wildfly to respect the @Singleton annotation (it created another instance when referencing)

       

      I think the way to go is writing a module, but havent been able to do it and couldnt find clear documentation on how to do it (everything I found referred to how to wrap a JDBC driver as a module, for example).

       

      If someone did something like this in the past, or know how to do it, please HELPPPPPP!!!! I've been two days with this now... and am quite desperate.  Perhaps arungupta?

       

      Kind regards!

       

      Juan Martin