Packaging and deploying the bean

Creation of the EJB jar package involves building a JAR archive containing the EJB classes and deployment descriptors. To build the EJB jar for the Interest example simply cd to the examples/build directory of the documentation examples source tree and execute the following ant command:

bash-2.04$ ant intro-interest-jar       
Buildfile: build.xml



     [echo] Using JBoss directory=/tmp/JBoss-2.2.2
     [echo] Using classpath=/tmp/JBoss-2.2.2/client/ejb.jar:/tmp/JBoss-2.2.2/client/jaas.jar:/tmp/JBoss-2.2.2/client/jbosssx-client.jar:/tmp/JBoss-2.2.2/client/jboss-client.jar:/tmp/JBoss-2.2.2/client/jnp-client.jar:/tmp/tomcat/lib/servlet.jar:/tmp/examples/${build.classes.dir}
     [echo] Using Source directory=/tmp/examples
     [echo] Using Build directory=/tmp/examples/build-examples


    [javac] Compiling 4 source files to /tmp/examples/build-examples/interest/classes

    [mkdir] Created dir: /tmp/examples/build-examples/interest/META-INF
     [copy] Copying 1 file to /tmp/examples/build-examples/interest/META-INF
     [copy] Copying 1 file to /tmp/examples/build-examples/interest/META-INF
      [jar] Building jar: /tmp/examples/build-examples/interest/interest.jar


Total time: 2 seconds

This has compiled the EJB classes and created the ejb-jar for deployment. If got a java.lang.NoClassDefFoundError here instead of a successful created jar file try clearing your classpath. The contents of the interest.jar include the structure we discussed previously as shown by running the jar -tvf command:

bash-2.04$ jar -tvf /tmp/examples/build-examples/interest/interest.jar
     0 Sun Jun 24 22:55:52 PDT 2001 META-INF/
    46 Sun Jun 24 22:55:52 PDT 2001 META-INF/MANIFEST.MF
     0 Sun Jun 24 22:55:52 PDT 2001 org/
     0 Sun Jun 24 22:55:52 PDT 2001 org/jboss/
     0 Sun Jun 24 22:55:52 PDT 2001 org/jboss/docs/
     0 Sun Jun 24 22:55:52 PDT 2001 org/jboss/docs/interest/
   246 Sun Jun 24 22:55:52 PDT 2001 org/jboss/docs/interest/Interest.class
  1177 Sun Jun 24 22:55:52 PDT 2001 org/jboss/docs/interest/InterestBean.class
   296 Sun Jun 24 22:55:52 PDT 2001 org/jboss/docs/interest/InterestHome.class
   599 Sun Jun 24 22:55:52 PDT 2001 META-INF/ejb-jar.xml
   220 Sun Jun 24 22:55:52 PDT 2001 META-INF/jboss.xml

To deploy the Bean on the server, all that's necessary is to copy the interest.jar file to the JBOSS_DIST/deploy directory of your JBoss installation. You can do this as often as you like. The server will detect that the file has changed and automatically re-deploy it. With the JBoss server running, deploy the jar by running ant intro-interest-deploy from the examples/build directory. During deployment you should see messages similar to the following on the server console:

[Auto deploy] Auto deploy of file:/tmp/JBoss-2.2.2/deploy/interest.jar
[J2EE Deployer Default] Deploy J2EE application: file:/tmp/JBoss-2.2.2/deploy/interest.jar
[J2EE Deployer Default] Create application interest.jar
[J2EE Deployer Default] install module interest.jar
[Container factory] Deploying:file:/tmp/JBoss-2.2.2/tmp/deploy/Default/interest.jar
[Verifier] Verifying file:/tmp/JBoss-2.2.2/tmp/deploy/Default/interest.jar/ejb1001.jar
[Container factory] Deploying Interest
[Container factory] Deployed application: file:/tmp/JBoss-2.2.2/tmp/deploy/Default/interest.jar
[J2EE Deployer Default] J2EE application: file:/tmp/JBoss-2.2.2/deploy/interest.jar is deployed.

If you see a message like this:

[Auto deploy] Auto deploy of file:/tmp/JBoss-2.2.2/deploy/interest.jar
[J2EE Deployer Default] Deploy J2EE application: file:/tmp/JBoss-2.2.2/deploy/interest.jar 
[Auto deploy] Deployment failed:file:/tmp/JBoss-2.2.2/deploy/interest.jar

then no EJBs have been deployed -- the server always reports the EJBs that it detects. This usually means that the deployment descriptor ejb-jar.xml is badly structured, or missing, or in the wrong directory.

You should now have the Interest EJB deployed on the server. We will now go over a simple test client that runs one of its methods, just to verify that it's working.