It is very easy to create a Stateless Bean with EJB 3.0. All bean types are homeless in EJB 3.0 so all you have to do to
create a Stateless bean is to create a bean class and have it implement at least one interface.
Take a look at CalculatorBean.java
CalculatorBean is defined as a stateless session bean through the <session> and <session-type> elements. This marks the class as a stateless bean and
the deployer will deploy that class as a stateless bean EJB container.
CalculatorBean also implements two interfaces. One is the remote interface of the EJB the other is the local interface.
Take a look at CalculatorRemote.java. To define this as the remote
interface of Calculator bean you specify the interface with the <remote> tag. Similar for
CalculatorLocal.java as you need to specify the local
interface with the <local> tag.
The Calculator bean will have two JNDI bindings for the remote and Local interface. By default, JBoss will use ejbName/local and ejbName/remote for the local and
remote interfaces, respectively.
Open up Client.java. You'll see that it looks up the stateless bean under
"ejbName/remote". 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 run
[java] 2004-10-06 19:10:35,857 INFO org.jboss.remoting.InvokerRegistry[main] - Failed to load soap remoting transpo
[java] 1 + 1 = 2
[java] 1 - 1 = 0
The INFO message you can ignore. It will be fixed in later releases of JBoss 4.0.
EJB 3.0 beans must be packaged in a JAR file with the suffix .jar. 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.