2

I have made a simple project to test the EJB3 implementation.

Using maven I created into the project 3 modules respectively "MyEjb" the EJB, "MyWeb" the war, "MyWeb2" another war. The war module are the client of the EJB.

The problem is that when I deploy the EAR, the console says that there are 3 EJB context created one for each modules. The EJB context of the module MyEjb is not shared between the wars moduls, each of it take the data from each own MyEjb dependency.

I have to create the EJB interfaces in a separate JAR? I use Jboss as application server.

Here the full project: https://github.com/AndreaCatania/EjbTest

Here the console:

[0m[0m09:32:18,735 INFO    [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named TheNamer in deployment unit deployment "MyEjbs-1.0-SNAPSHOT.jar" are as follows:

    java:global/MyEjbs-1.0-SNAPSHOT/TheNamer!com.andreacatania.test.RemoteNamer
    java:app/MyEjbs-1.0-SNAPSHOT/TheNamer!com.andreacatania.test.RemoteNamer
    java:module/TheNamer!com.andreacatania.test.RemoteNamer
    java:jboss/exported/MyEjbs-1.0-SNAPSHOT/TheNamer!com.andreacatania.test.RemoteNamer
    java:global/MyEjbs-1.0-SNAPSHOT/TheNamer
    java:app/MyEjbs-1.0-SNAPSHOT/TheNamer
    java:module/TheNamer

[0m[0m09:32:19,137 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-5) JNDI bindings for session bean named TheNamer in deployment unit deployment "MyWeb.war" are as follows:

    java:global/MyWeb/TheNamer!com.andreacatania.test.RemoteNamer
    java:app/MyWeb/TheNamer!com.andreacatania.test.RemoteNamer
    java:module/TheNamer!com.andreacatania.test.RemoteNamer
    java:jboss/exported/MyWeb/TheNamer!com.andreacatania.test.RemoteNamer
    java:global/MyWeb/TheNamer
    java:app/MyWeb/TheNamer
    java:module/TheNamer

[0m[0m09:32:19,142 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-6) JNDI bindings for session bean named TheNamer in deployment unit deployment "MyWeb2.war" are as follows:

    java:global/MyWeb2/TheNamer!com.andreacatania.test.RemoteNamer
    java:app/MyWeb2/TheNamer!com.andreacatania.test.RemoteNamer
    java:module/TheNamer!com.andreacatania.test.RemoteNamer
    java:jboss/exported/MyWeb/TheNamer!com.andreacatania.test.RemoteNamer
    java:global/MyWeb2/TheNamer
    java:app/MyWeb2/TheNamer
    java:module/TheNamer
Andrea Catania
  • 1,361
  • 3
  • 21
  • 37
  • To work with separation of concerns you should make separate modules for client or take a look [into the docs](http://maven.apache.org/plugins/maven-ejb-plugin/examples/generating-ejb-client.html) how to generate the client. – khmarbaise Feb 25 '15 at 09:12

1 Answers1

0

You will need to filter out what should go into the ejb-client module and not. If you don't specify this, the client jar will be exactly the same as the normal jar. One easy way to accomplish this is to have your interfaces in a package named api and just include stuff matching this in the client jar.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ejb-plugin</artifactId>
    <version>2.3</version>
    <configuration>
         <!--ejbVersion>3.1</ejbVersion-->
         <generateClient>true</generateClient>
         <clientIncludes>
            <clientInclude>**/api/*</clientInclude>
         </clientIncludes>
    </configuration>
</plugin>
P-a Bäckström
  • 529
  • 2
  • 7
  • Please use an up-to-date version of maven-ejb-plugin (2.5) – khmarbaise Feb 25 '15 at 09:14
  • Thanks, now I see only 1 EJB running... but I have another error: Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014544: No EJB found with interface of type 'com.andreacatania.ejbapi.RemoteNamer' for binding com.andreacatania.myweb2.test.servlet.Test/namer – Andrea Catania Feb 25 '15 at 10:02
  • I've reviewed your code a bit. `@Remote` should only be used if access needs to be granted from outside the application. Use `@Local` instead. You should also remove the annotation from the interface and have it on your bean instead, i.e `@Local(LocalNamer.class)` – P-a Bäckström Feb 25 '15 at 11:04
  • Sorry, just to be clear. Remove the `@Remote` annotation, and use `@Local` instead on your interface. On the bean class, you will still need to implement the interface, but also annotate the class with `@Local(LocalNamer.class)` (provided that you've changed the name of the interface too) – P-a Bäckström Feb 25 '15 at 11:15