Deploying an EJB JAR to JBoss

In the JDeveloper integrated development environment, you can create generic J2EE EJBs. JDeveloper also supports direct deployment of EJB applications to a standalone OC4J instance, Oracle Application Server, and WebLogic 6.1 or 7.0SP1. In addition, JDeveloper supports creation of a J2EE EJB JAR file for deployment to JBoss 3.0.4 (with Tomcat 4.1.12).

To deploy EJB JARs to JBoss:

  1. Start JBoss using the setvars.bat script on Windows.

    On UNIX (Bourne Shell), set the JAVA_HOME environment variable and add the Java2 SDK's bin directory to your PATH. For example:

    export JAVA_HOME=/usr/java/jdk1.4
    export PATH=${PATH}:${JAVA_HOME}/bin

  2. Execute the run script in the JBoss\bin directory. For example:
    C:\JBoss-3.0.4\bin

    After JBoss is started, several lines appear in the command shell.

  3. Create a library in JDeveloper for JBoss. The client side libraries from JBoss are located in the client directory under the JBoss directory, for example C:\JBoss-3.0.4\client, and are used to test an EJB deployed within JBoss. See Including Libraries in a Project.
  4. In JDeveloper,create a new Stateless Session Bean. In the Enterprise JavaBean Wizard, click Next to accept all defaults, then click Finish.
  5. (Optional) Create a jboss.xml file if you want to support JBoss-specific configuration options for the EJBs. For example, you can modify the JNDI name of your EJB resources or include custom containers in jboss.xml. See Creating a jboss.xml file.
  6. Create a test client for your EJB by right-clicking the EJB node in the Navigator and choosing the Create Sample Java Client context menu option.
  7. Choose Connect to Remote App Server and ignore the values for the J2EE Application Name and Oracle9iAS Connection Name. See Running and Testing EJB Methods.
  8. The default test client needs to be modified for use with JBoss because JNDI properties for JBoss are different from Oracle Application Server. Replace the initial environment with the following:

    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    env.put(Context.PROVIDER_URL, "localhost");
    env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );

  9. Add code to invoke the setInfo and getInfo methods previously added by the EJB Class Designer. For example, the test application is modified to invoke these methods:
     
    	Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        env.put(Context.PROVIDER_URL, "localhost");
        env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        Context ctx = new InitialContext(env);
        MySessionEJBHome mySessionEJBHome = (MySessionEJBHome)ctx.lookup("MySessionEJB");
        // Use one of the create() methods below to create a new instance
        MySessionEJB mySessionEJB = mySessionEJBHome.create( );
        // Call any of the Remote methods below to access the EJB
        mySessionEJB.setInfo( "Hello World" );
        System.out.println( MySessionEJB.getInfo() );
  10. Create an EJB Deployment Profile keeping the default name, ejb1.deploy.
    1. Keep the default settings in the J2EE EJB Module Deployment Profile Settings panel.
  11. In the Navigator, select and right-click ejb1.deploy and choose Deploy to JAR file from the context menu. The EJB module is packaged as an EJB JAR file and saved to the local directory or mapped network drive which you specified in the EJB deployment profile settings panel.
  12. In the Deployment Log window, a message indicates the location of the newly created .jar file. For example:

    Beginning to deploy to the EJB JAR file...
    Wrote EJB .jar file to D:\jdev\mywork\Workspace2\Project1\ejb1.jar
    ---- Deployment finished. ---- July 6, 2002 2:58:05 PM

  13. Copy this file to the JBoss/deploy directory.
  14. Once JBoss detects that a file has changed in this location, it will automatically deploy your EJB. After JBoss has deployed the EJB, a message will be displayed in the console window in which JBoss was started.

Testing the EJB in JBoss

  1. In JDeveloper, edit your project properties, remove the J2EE and Oracle9iAS libraries, and add the JBoss library to your project.
  2. Run the test client.
  3. Verify that "Hello World" is displayed in the Message Log.

See Also: