7 Replies Latest reply on Aug 30, 2002 11:50 AM by Javier Torreblanca Beltran

    where is the samples?

    Lars Hagrot Newbie

      I have succeeded in downloading and starting JBoss but now I wonder: where is the samples?

      I want a single simple sample which uses cmp2.0 and also have a simple java client.

        • 1. Re: where is the samples?
          Jason Brome Newbie

          Have you checked out the JBoss 3.0 Getting Started docs, and the accompanying examples?


          • 2. Re: where is the samples?
            Bakul Mukherjee Newbie

            I checked the Quickstart guide. There is nothing on EJBs. There were no examples either. Thers is mention of a template project. Other than that I couldn't find any samples/examples of any sort? Any idea on where I can find some?


            • 3. Re: where is the samples?
              Javier Torreblanca Beltran Newbie

              I followed the "Mastering Enterprise JavaBeans" (Ed Roman) book examples. The examples are working in JBoss-3.0.1_Tomcat-4.0.4. I only changed the xml configuration files. The EAR, WAR and JAR structure file is very important to deploy applications.
              You can get free this e-book at :

              In this reply I explain a Session Stateless Session bean and in other replies I will send you examples of Stateful Session bean, Bean-Managed Persistent Entity Bean, Container-Managed Persistent Entity Bean and Message-driven bean.
              I need to prepare every document, let me a little time.

              Stateless Session Bean

              This Stateless Session bean example shows the date.

              1. Create the following files : PrimerEJB.java, PrimerHome.java and Primer.java at


              Source of PrimerEJB.java
              package com.ejb1;

              import javax.ejb.SessionBean;
              import javax.ejb.EJBException;
              import javax.ejb.SessionContext;
              import java.rmi.RemoteException;
              import java.util.Date;

              public class PrimerEJB implements SessionBean {
              public String recuperaTiempo() {
              return "La fecha es : " + new Date().toString();

              public void ejbCreate() {}
              public void ejbPassivate() {}
              public void ejbActivate() {}
              public void ejbRemove() {}
              public void setSessionContext(SessionContext context) {}

              The recuperaTiempo method retrieves the date.

              Source of PrimerHome.java
              package com.ejb1;

              import javax.ejb.EJBHome;
              import javax.ejb.CreateException;
              import java.rmi.RemoteException;
              import com.ejb1.Primer;

              public interface PrimerHome extends EJBHome {
              public Primer create() throws CreateException, RemoteException;

              Source of Primer.java
              package com.ejb1;
              import javax.ejb.EJBObject;
              import java.rmi.RemoteException;

              public interface Primer extends EJBObject {
              public String recuperaTiempo() throws RemoteException;

              2. Compile PrimerEJB.java, PrimerHome.java and Primer.java in [drive]:\examples\src.

              javac -d d:\examples\src -classpath %classpath%;.;d:\examples\src;d:\jboss-3.0.1_Tomcat-4.0.4\client\jboss-j2ee.jar *.java

              3. The before step creates the following directory structure:


              4. Create the jsp (primerEJB.jsp)

              Source of primerEJB.jsp
              <%@ page import="javax.naming.InitialContext,
              long t1 = System.currentTimeMillis();
              Properties props = new Properties();
              props.put(Context.PROVIDER_URL, "");

              Context ctx = new InitialContext(props);
              PrimerHome home = (PrimerHome)ctx.lookup("ejb/Primer");
              Primer bean = home.create();
              String time = bean.recuperaTiempo();
              long t2 = System.currentTimeMillis();

              p { font-family:Verdana;font-size:12px; }

              Mensaje recibido del bean = "<%= time %>".Tiempo transcurrido :
              <%= (t2 - t1) %> ms.


              You need to change the following line:

              props.put(Context.PROVIDER_URL, "");

              change to your IP ADDRESS JBOSS_TOMCAT SERVER :

              props.put(Context.PROVIDER_URL, "[IP ADDRESS SERVER]:1099");

              5. Create ejb-jar.xml in [drive]:\examples\src\META-INF

              Source of ejb-jar.xml
              <?xml version="1.0"?>
              <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems,
              Inc.//DTD Enterprise JavaBeans 2.0//EN"




              6. Create jboss.xml in [drive]:\examples\src\META-INF

              Source of jboss.xml
              <?xml version='1.0' encoding='UTF-8' ?>
              <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS//EN"





              The value in <jndi-name> tag is equal to the following line used in primerEJB.jsp :

              PrimerHome home = (PrimerHome)ctx.lookup("ejb/Primer");

              7. Create [drive]:\examples\src\WEB-INF\classes and then copy the EJB classes with their package structure (PrimerEJB.class, PrimerHome.class and Primer.class).

              the result is :


              8. Create the JAR file (primerEJB.jar). Change to [drive]:\examples\src directory and use the following instruction :

              jar -cvfM primerEJB.jar com META-INF

              9. Create the WAR file (primerEJB.war). Change to [drive]:\examples\src directory and use the following instruction :

              jar -cvfM primerEJB.war WEB-INF primerEJB.jsp

              10. Copy the JAR file (primerEJB.jar) and WAR file (primerEJB.war) to [drive]:\examples

              11. Create application.xml in [drive]:\examples\META-INF directory.

              Source of application.xml
              <?xml version="1.0" encoding="ISO-8859-1"?>

              <display-name>Primer EJB</display-name>




              The value in <web-uri> tag is the name of your WAR file.
              The value in <context-root> tag is the context of your application.
              The value in tag is the name of your JAR file.

              12. Create the EAR file (primerEJB.ear). Change to [drive]:\examples directory and use the following instruction :

              jar -cvfM primerEJB.ear primerEJB.jar primerEJB.war META-INF

              13. Copy the EAR file to %JBOSS_HOME%\server\default\deploy.

              14. Run JBoss-Tomcat Server

              15. Test the application :

              http://[IP ADDRESS JBOSS-TOMCAT SERVER]:8080/primerEJB/primerEJB.jsp

              You can automate this building process using Ant.

              In the next reply I will send you in attachment the EAR file (primerEJB.ear)



              • 4. Re: where is the samples?
                Javier Torreblanca Beltran Newbie

                Here is the attachment. PrimerEJB.ear



                • 5. Re: where is the samples?
                  Javier Torreblanca Beltran Newbie

                  In this moment I found in the forum a Monson-Haefel book using EJB with JBoss, the address is :




                  • 6. Re: where is the samples?
                    reneticus Newbie


                    I've been following your nice sample in how to create and deploy a sample servlet and JSP. And I made it to work, thanks so much!

                    However, I deployed your PrimerEJB.ear sample and it deployed without errors, but when I ran it, it errored-out operation timeout exception. Something like "Failed to connect to". I'm using the Jboss-Jetty bundle. Any idea what this error means?


                    • 7. Re: where is the samples?
                      Javier Torreblanca Beltran Newbie

                      I´m sorry. I did a mistake with attachment PrimerEJB.ear file, because it doesn´t work. I create this EAR with my IP ADDRESS SERVER (
                      You need create a new EAR file with your IP ADDRESS SERVER (Step 4 - Creation of JSP file). You need change in JSP file the following line :

                      props.put(Context.PROVIDER_URL, "[IP ADDRESS SERVER]:1099");