Enterprise Java Development@TOPIC@
Useful in WAR deployments
`-- WEB-INF `-- WEB-INF |-- classes | `-- info | `-- ejava | `-- examples | `-- ejb | `-- basic | `-- webejb | `-- WebGreeterEJB.class |-- jboss-web.xml `-- lib `-- ejb-basic-ejb-4.0.0-SNAPSHOT.jar
WARs may host
imported EJBs - developed in a separate EJB module
embedded EJBs - developed within this module
(WebGreeterEJB is a copy/paste clone of GreeterEJB)
EJB module deployed within WAR
20:47:51,929 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-2) JNDI bindings for session bean named GreeterEJB in deployment unit deployment "ejb-basic-war.war" are as follows: java:global/ejb-basic-war/GreeterEJB!info.ejava.examples.ejb.basic.ejb.GreeterRemote java:app/ejb-basic-war/GreeterEJB!info.ejava.examples.ejb.basic.ejb.GreeterRemote java:module/GreeterEJB!info.ejava.examples.ejb.basic.ejb.GreeterRemote java:jboss/exported/ejb-basic-war/GreeterEJB!info.ejava.examples.ejb.basic.ejb.GreeterRemote java:global/ejb-basic-war/GreeterEJB java:app/ejb-basic-war/GreeterEJB java:module/GreeterEJB 20:47:51,970 INFO [org.jboss.weld.deployer] (MSC service thread 1-2) JBAS016005: Starting Services for CDI deployment: ejb-basic-war.war 20:47:51,988 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016008: Starting weld service for deployment ejb-basic-war.war 20:47:52,353 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017534: Registered web context: /ejb-basic-war
JBoss server prints out JNDI names to access EJB through...
@Remote
No interface
Globally within the server (java:global)
Within the deployed application (java:app)
Within the EJB module (java:module)
External to server (java:global/exported)
Derive remote client JNDI name from "exported" name
ejb-basic-war/GreeterEJB!info.ejava.examples.ejb.basic.ejb.GreeterRemote
Local and No-interface interfaces are not exposed to remote clients
Embedded EJBs have same naming structure
java:global/ejb-basic-war/WebGreeterEJB!info.ejava.examples.ejb.basic.ejb.GreeterRemote java:app/ejb-basic-war/WebGreeterEJB!info.ejava.examples.ejb.basic.ejb.GreeterRemote java:module/WebGreeterEJB!info.ejava.examples.ejb.basic.ejb.GreeterRemote java:jboss/exported/ejb-basic-war/WebGreeterEJB!info.ejava.examples.ejb.basic.ejb.GreeterRemote java:global/ejb-basic-war/WebGreeterEJB java:app/ejb-basic-war/WebGreeterEJB java:module/WebGreeterEJB
packaging=war
Configures plugin to perform WAR-like packaging of dependencies
scope=compile dependencies
Name upstream Maven modules that should be deployed in WEB-INF/classes
build.finalName
Helps eliminate version# from being in JNDI name
<project>
<groupId>info.ejava.examples.ejb.basicejb</groupId>
<artifactId>ejb-basic-war</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ejb-basic-ejb</artifactId>
<version>${project.version}</version>
<type>ejb</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>ejb-basic-war</finalName>
</build>
</project>
If the WAR is ever deployed within an EAR with a sibling EJB as its dependency -- the scope of the dependency should be defined as "provided" and not "compile". The "compile" scope will always deploy named artifacts (and their dependencies) within the WEB-INF/lib directory of the WAR. If the EAR is deploying them as well -- you will end up with duplicate deployments (one from the EAR and one from the WAR) and will eventally fail.
Support for embedded EJB development will require standard POJO and EJB dependencies
<!-- for embedded code/EJBs -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<scope>provided</scope>
</dependency>
Add EAR artifact as a scope=compile dependency when deploying from separate (test) module
<dependencies>
...
<!-- packages being deployed must be a dependency -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ejb-basic-war</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>compile</scope>
</dependency>
...
</dependencies>
Declare EAR artifact to be deployed
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<!-- artifacts to deploy to server -->
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>ejb-basic-war</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
</plugin>
</plugins>
</build>
Details of cargo-maven2-plugin are provided elsewhere