11 Replies Latest reply on Sep 5, 2002 3:59 PM by sheldon

    I need a single example

    sheldon Newbie

      I just install the jboss and don't know how to use it.

      The examples on jboss website doesn't work for me.

      Can anyone give me a single example to run it. Please include every file and the compile command.

      I am so appreciate for your help.

        • 1. Re: I need a single example
          Jason Brome Newbie

          Have you read through the JBoss 3.0 quickstart docs yet?


          If you have, what particular problems were you having?

          • 2. Re: I need a single example
            Javier Torreblanca Beltran Newbie

            Here is the procedure for JSPs :

            1. Write the JSP
            Example (uno.jsp) :

            <%@ page import="java.text.*,

            Date d = new Date();
            String hoy = DateFormat.getDateInstance().format(d);
            La Fecha de hoy es :
            <%= hoy %>

            2. Create a WAR file with JSP file. Use the following command :

            jar -cvfM uno.war uno.jsp

            3. Create an application.xml file in META-INF directory. You need set the correct values in <web-uri> tag and <context-root> tag.

            web-uri = WAR name file

            Example (application.xml):

            <?xml version="1.0" encoding="ISO-8859-1"?>



            4. Create a EAR file with WAR file and application.xml file. Use the following command :

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

            5. Copy this EAR file in %JBOSS_HOME%\server\default\deploy

            6. Run the JBoss-Tomcat server.

            7. Test the JSP. Use the following URL:

            http://[IP ADDRESS SERVER]:8080/uno/uno.jsp

            The first time is slow because JBoss-Tomcat compiles the JSP file but the next time is fast.


            1. Write your servlet. For example


            package com.servlet;

            import java.io.*;
            import javax.servlet.*;
            import javax.servlet.http.*;

            public class Dos extends HttpServlet {
            public void doGet(HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {

            PrintWriter out = response.getWriter();
            out.println("Hello World");

            2. Compile your servlet. Use the following command :

            javac -classpath d:\jboss-3.0.1_Tomcat-4.0.4\catalina\common\lib\servlet.jar Dos.java

            3. Create a WEB-INF directory.

            4. Create a classes directory in WEB-INF directory and copy Dos.class.

            WEB-INF (Subdirectory)
            classes (Subdirectory) ---
            com (subdirectory)----
            servlet (subdirectory)
            Dos.class (Java Class)

            5. Create a web.xml file in WEB-INF directory.

            For example:

            <?xml version="1.0" encoding="ISO-8859-1"?>

            <!DOCTYPE web-app
            PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"



            6. Create a META-INF directory.

            7. Create an application.xml file in META-INF directory.

            For example:


            <?xml version="1.0" encoding="ISO-8859-1"?>



            8. Create a WAR file. Use the following command :

            jar -cvfM dos.war WEB-INF

            9. Create a EAR file. Use the following command :

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

            10. Copy the EAR file in %JBOSS_HOME%\server\default\deploy

            11. Run the JBoss-Tomcat server.

            12. Test the Servlet. Use the following URL:

            http://[IP ADDRESS SERVER]:8080/dos/servlet/Dos



            • 3. Re: I need a single example
              Javier Torreblanca Beltran Newbie

              I send you in attachment the following files :

              uno.ear (JSP example)
              dos.ear (Servlet example)

              Test it.



              • 4. Re: I need a single example
                Lars Willemsens Newbie

                Thank you very much, it worked perfectly.

                • 5. Re: I need a single example
                  Bakul Mukherjee Newbie

                  Is there any example which shows how to write and deploy Session and Entity Beans, Clients, configure Datasources etc. for JBoss3. I couldn't find any examples shipped with the server and the Getting started docs doesn't contain nay information on EJBs. Those chapters are empty.

                  I have my own EJB jar files but I need to know what extra to do deploy my jar files on JBoss, what files I need to put where and what to put in the classpath.


                  • 6. Re: I need a single example
                    Tom Yang Newbie

                    Hi all:
                    I followd Torreblanca's instruction exactly (actually, I copied and pasted his example for the jsp page uno.jsp), but when I load the page from the Web browser, I got the error message:

                    type Status report

                    message No Context configured to process this request

                    description The server encountered an internal error (No Context configured to process this request) that prevented it from fulfilling this request.

                    Can someone please help me to figure out what is wrong? Thank you very much in advance!


                    • 7. Re: I need a single example
                      Tom Yang Newbie

                      Hi all:
                      I got the answer to my question. I forgot to include the servlet.jar in my CLASSPATH. Thanks all the for help in the posting.


                      • 8. Re: I need a single example
                        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

                        14. 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)



                        • 9. Re: I need a single example
                          Javier Torreblanca Beltran Newbie

                          Here is the file attachment (primerEJB.ear).



                          • 10. Re: I need a single example
                            Javier Torreblanca Beltran Newbie

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




                            • 11. Re: I need a single example
                              sheldon Newbie

                              Thank you so much.
                              It's very helpful for me.
                              I have some idea what's jboss, ejb now.