3 Replies Latest reply on Mar 14, 2006 6:58 PM by Uli de Maddalena

    JBoss EJB 3.0 Documentation>Tutorial -->How to build?

    Christoph Gerstle Newbie

      Hi!
      I have installed jboss-4.0.4RC1...
      I want to walk to the EJB 3.0 tutorial(s) (on http://docs.jboss.org/ejb3/app-server/tutorial/). My problem is the "Building and Running". There is the hint "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. (I can´t find anything there)
      Windows: $ set JBOSS_HOME=<where your jboss 4.0 distribution is> (I did)
      $ ant
      $ ant run


      Hmm, ANT needs a build.xml file, or?

      HELP;)

      thx

        • 1. Re: JBoss EJB 3.0 Documentation>Tutorial -->How to build?
          Christoph Gerstle Newbie

           

          "ChristophG" wrote:
          Hi!
          I have installed jboss-4.0.4RC1...
          I want to walk to the EJB 3.0 tutorial(s) (on http://docs.jboss.org/ejb3/app-server/tutorial/). My problem is the "Building and Running". There is the hint "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. (I can´t find anything there)
          Windows: $ set JBOSS_HOME=<where your jboss 4.0 distribution is> (I did)
          $ ant
          $ ant run


          Hmm, ANT needs a build.xml file, or?

          HELP;)

          thx


          Well, I found a build.xml ofr the first tutorial (on http://docs.jboss.org/ejb3/app-server/tutorial/stateless/build.xml)
          I had to change <property name="jboss.server.config" value="all"/>
          to <property name="jboss.server.config" value="default"/> (line 13). That was the default when I was using the installer.


          <?xml version="1.0"?>
          
          <!-- ======================================================================= -->
          <!-- JBoss build file -->
          <!-- ======================================================================= -->
          
          <project name="JBoss" default="ejbjar" basedir=".">
          
           <property file="../local.properties" />
           <property environment="env"/>
           <property name="src.dir" value="${basedir}/src"/>
           <property name="jboss.home" value="${env.JBOSS_HOME}"/>
           <property name="jboss.server.config" value="all"/>
           <property name="build.dir" value="${basedir}/build"/>
           <property name="build.classes.dir" value="${build.dir}/classes"/>
          
           <!-- Build classpath -->
           <path id="classpath">
           <pathelement location="${basedir}"/>
           <fileset dir="${jboss.home}/lib">
           <include name="**/*.jar"/>
           </fileset>
           <fileset dir="${jboss.home}/server/${jboss.server.config}/lib">
           <include name="**/*.jar"/>
           </fileset>
           <fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/ejb3.deployer">
           <include name="*.jar"/>
           </fileset>
           <fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/jboss-aop-jdk50.deployer">
           <include name="*.jar"/>
           </fileset>
           <pathelement location="${build.classes.dir}"/>
           <!-- So that we can get jndi.properties for InitialContext -->
           </path>
          
           <property name="build.classpath" refid="classpath"/>
          
           <!-- =================================================================== -->
           <!-- Prepares the build directory -->
           <!-- =================================================================== -->
           <target name="prepare">
           <mkdir dir="${build.dir}"/>
           <mkdir dir="${build.classes.dir}"/>
           </target>
          
           <!-- =================================================================== -->
           <!-- Compiles the source code -->
           <!-- =================================================================== -->
           <target name="compile" depends="prepare">
           <javac srcdir="${src.dir}"
           destdir="${build.classes.dir}"
           debug="on"
           deprecation="on"
           optimize="off"
           includes="**">
           <classpath refid="classpath"/>
           </javac>
           </target>
          
           <target name="ejbjar" depends="compile">
           <jar jarfile="build/tutorial.jar">
           <fileset dir="${build.classes.dir}">
           <include name="**/*.class"/>
           </fileset>
           </jar>
           <copy file="build/tutorial.jar" todir="${jboss.home}/server/${jboss.server.config}/deploy"/>
           </target>
          
           <target name="run" depends="ejbjar">
           <java classname="org.jboss.tutorial.stateful.client.Client" fork="yes" dir=".">
           <classpath refid="classpath"/>
           </java>
           </target>
          
           <!-- =================================================================== -->
           <!-- Cleans up generated stuff -->
           <!-- =================================================================== -->
           <target name="clean.db">
           <delete dir="${jboss.home}/server/${jboss.server.config}/data/hypersonic"/>
           </target>
          
           <target name="clean">
           <delete dir="${build.dir}"/>
           <delete file="${jboss.home}/server/${jboss.server.config}/deploy/tutorial.jar"/>
           </target>
          
          
          </project>



          $ant
          Buildfile: build.xml

          prepare:

          compile:
          [javac] Compiling 4 source files to [..]\build\classes
          [javac] [..]\src\CalculatorRemote.java:28: cannot find symbol
          [javac] symbol: class Calculator
          [javac] public interface CalculatorRemote extends Calculator
          ...
          [javac] 5 errors

          BUILD FAILED


          any ideas?



          • 2. Re: JBoss EJB 3.0 Documentation>Tutorial -->How to build?
            Christian Lischnig Newbie

            Hello!

            Did anyone find out how to get startet with these tutorials? I still haven't found the tutorial.jar, where can I get this file?

            Thanks for any suggetions.

            Kind regards Chris

            • 3. Re: JBoss EJB 3.0 Documentation>Tutorial -->How to build?
              Uli de Maddalena Newbie

              Hello,
              here is the build file i used

              <?xml version="1.0"?>
              
              <!-- ======================================================================= -->
              <!-- JBoss build file -->
              <!-- ======================================================================= -->
              
              <project name="JBoss" default="ejbjar" basedir=".">
              
               <property file="./local.properties" />
               <property environment="env"/>
               <property name="src.dir" value="${basedir}/src"/>
               <property name="jboss.home" value="${env.JBOSS_HOME}"/>
               <property name="jboss.server.config" value="default"/>
               <property name="build.dir" value="${basedir}/build"/>
               <property name="build.classes.dir" value="${build.dir}/classes"/>
              
               <!-- Build classpath -->
               <path id="classpath">
               <pathelement location="${basedir}"/>
               <fileset dir="${jboss.home}/lib">
               <include name="**/*.jar"/>
               </fileset>
               <fileset dir="${jboss.home}/server/${jboss.server.config}/lib">
               <include name="**/*.jar"/>
               </fileset>
               <fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/ejb3.deployer">
               <include name="*.jar"/>
               </fileset>
               <fileset dir="${jboss.home}/server/${jboss.server.config}/deploy/jboss-aop-jdk50.deployer">
               <include name="*.jar"/>
               </fileset>
               <pathelement location="${build.classes.dir}"/>
               <!-- So that we can get jndi.properties for InitialContext -->
               </path>
              
               <property name="build.classpath" refid="classpath"/>
              
               <!-- =================================================================== -->
               <!-- Prepares the build directory -->
               <!-- =================================================================== -->
               <target name="prepare">
               <mkdir dir="${build.dir}"/>
               <mkdir dir="${build.classes.dir}"/>
               </target>
              
               <!-- =================================================================== -->
               <!-- Compiles the source code -->
               <!-- =================================================================== -->
               <target name="compile" depends="prepare">
               <javac srcdir="${src.dir}"
               destdir="${build.classes.dir}"
               debug="on"
               deprecation="on"
               optimize="off"
               includes="**">
               <classpath refid="classpath"/>
               </javac>
               </target>
              
               <target name="ejbjar" depends="compile">
               <jar jarfile="build/tutorial.jar">
               <fileset dir="${build.classes.dir}">
               <include name="**/*.class"/>
               </fileset>
               </jar>
               <copy file="build/tutorial.jar" todir="${jboss.home}/server/${jboss.server.config}/deploy"/>
               </target>
              
               <target name="run" depends="ejbjar">
               <java classname="org.jboss.tutorial.stateless.client.Client" fork="yes" dir=".">
               <classpath refid="classpath"/>
               </java>
               </target>
              
               <!-- =================================================================== -->
               <!-- Cleans up generated stuff -->
               <!-- =================================================================== -->
               <target name="clean.db">
               <delete dir="${jboss.home}/server/${jboss.server.config}/data/hypersonic"/>
               </target>
              
               <target name="clean">
               <delete dir="${build.dir}"/>
               <delete file="${jboss.home}/server/${jboss.server.config}/deploy/tutorial.jar"/>
               </target>
              
              
              </project>
              


              for example create the following directories:

              c:\example
              c:\example\src\org\jboss\tutorial\stateless\bean
              c:\example\src\org\jboss\tutorial\stateless\client

              copy the build File to c:\example

              Create the following java files

              c:\example\src\org\jboss\tutorial\stateless\bean\Calculator.java

              package org.jboss.tutorial.stateless.bean;
              
              import javax.ejb.Stateless;
              
              public interface Calculator
              {
               public int add(int x, int y);
              
               public int subtract(int x, int y);
              }
              



              c:\example\src\org\jboss\tutorial\stateless\bean\CalculatorRemote.java

              package org.jboss.tutorial.stateless.bean;
              
              import javax.ejb.Remote;
              
              @Remote
              public interface CalculatorRemote extends Calculator
              {
              
              }
              


              c:\example\src\org\jboss\tutorial\stateless\bean\CalculatorBean.java
              package org.jboss.tutorial.stateless.bean;
              
              import javax.ejb.Stateless;
              
              @Stateless
              public class CalculatorBean implements CalculatorRemote, CalculatorLocal
              {
               public int add(int x, int y)
               {
               return x + y;
               }
              
               public int subtract(int x, int y)
               {
               return x - y;
               }
              }
              



              c:\example\src\org\jboss\tutorial\stateless\bean\CalculatorLocal.java
              package org.jboss.tutorial.stateless.bean;
              
              import javax.ejb.Local;
              
              
              @Local
              public interface CalculatorLocal extends Calculator
              {
              }
              




              c:\example\src\org\jboss\tutorial\stateless\client\Client.java

              package org.jboss.tutorial.stateless.client;
              
              import org.jboss.tutorial.stateless.bean.Calculator;
              import org.jboss.tutorial.stateless.bean.CalculatorRemote;
              
              import javax.naming.InitialContext;
              
              public class Client
              {
               public static void main(String[] args) throws Exception
               {
              
              
               System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
               System.setProperty("java.naming.provider.url", "localhost:1099");
              
              
               InitialContext ctx = new InitialContext();
               Calculator calculator = (Calculator) ctx.lookup("CalculatorBean/remote");
              
               System.out.println("1 + 1 = " + calculator.add(1, 1));
               System.out.println("1 - 1 = " + calculator.subtract(1, 1));
               }
              }
              


              here is my environment:
              JAVA_HOME=C:\Programme\Java\jdk1.5.0_05
              JBOSS_HOME=C:\Programme\jboss-4.0.4RC1
              ANT_HOME=C:\Programme\apache-ant-1.6.5

              be sure that jboss is running

              go to c:\example and start: ant


              after that start: ant run



              -----------
              Uli