JNDI Bindings and Multiple Transports
By default, session beans will bind to JNDI under the fully qualified name of their local and/or remote interface. You can override this behavior by defining your own @org.jboss.ejb3.LocalBinding or @org.jboss.ejb3.remoting.RemoteBinding.
Local Interface JNDI Binding.
To change the JNDI name for your local interface use the org.jboss.ejb3.LocalBinding annotation.
@Stateless
@LocalBinding(jndiBinding="custom/MySession")
public class MySessionBean implements MySession
{
}
Remote Interface JNDI Binding
To change the JNDI name for your remote interface use the org.jboss.ejb3.RemoteBindings annotation.
@Stateless
@RemoteBinding(jndiName="custom/remote/MySession")
public class MySessionBean implements MySession
{
}
Client
Open up Client.java. You'll see that it looks up the stateless bean under "Calculator". Also notice that there is no Home interface and you can begin executing on the stateless bean right away.
Building and Running
To build and run the example, make sure you have ejb3.deployer installed in JBoss 4.0.x and have JBoss running. See the reference manual on how to install EJB 3.0.
Unix: $ export JBOSS_HOME=<where your jboss 4.0 distribution is>
Windows: $ set JBOSS_HOME=<where your jboss 4.0 distribution is>
$ ant
$ ant run
run:
[java] 1 + 1 = 2
[java] 1 - 1 = 0
Jar structure
EJB 3.0 beans must be packaged in a JAR file with the suffix .ejb3. Running the ant script above creates a JAR file within the deploy/ directory of JBoss. All that needs to be in that jar is your server-side class files. So basically just the CalculatorBean and the interfaces it implements. JBoss will automatically browse the JAR file to determine if any EJBs are annotated by any classes within it. THere is no precompilation step.