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
The first thing to notice is that the class is tagged as @Stateless. 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. Currently, you can only have one remote and/or local interface.
Take a look at CalculatorRemote.java. To define this as the remote interface of Calculator bean
you only need to tag it as @Remote. Same goes for CalculatorLocal.java as it only needs to be marked as @Local for it to be the local interface of the CalculatorBean.
The Calculator bean will have two JNDI bindings for the @Remote and @Local interface. By default, JBoss will use the fully qualified class name of the interface as the JNDI name. This makes it very easy to reference the JNDI name in lookups as you can just do CalculatorRemote.class.getName().
Open up Client.java. You'll see that it looks up the stateless bean under its remote interface's fully qualified classname. 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] 2004-10-06 19:10:35,857 INFO org.jboss.remoting.InvokerRegistry[main] - Failed to load soap remoting transpo rt: org/apache/axis/AxisFault [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 .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.