1 Reply Latest reply on Aug 11, 2003 9:14 AM by masroor

    FINALLY: JBoss & Tomcat Standalone Approach

    masroor

      Hello there!

      Here is a way, how to integrate ein Standalone Tomcat with JBoss. It's pretty simple. It works with Tomcat4.1.27 and JBoss 3.2.2RC2.

      This is answer for these threads:
      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t= of all, you need to disable the MBeans of Tomcat (it's possible, that they cause problems). You can do this by commenting following lines in the server.xml like this:

      <!--Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
      debug="0"/-->
      <!--Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
      debug="0"/-->

      2.
      After this, copy all JBoss-Client specific libs into the /shared/lib directory of Tomcat. They are located in the /client directory of JBoss.

      3.
      To call a EJB on JBoss, you need to use the JBoss-specific JNDI properties too. Sometimes, placing the jndi.properties file into the /WEB-INF/classes will do this. You can find this file in the /server/default/conf directory. If Tomcat ignores this, you have to set the properties manually in the source code. Here ist an example:


      Properties env = new Properties();
      env.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      env.setProperty("java.naming.provider.url", "jnp://localhost:1099/");
      env.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");

      try
      {
      // Get a naming context
      InitialContext jndiContext = new InitialContext(env);
      System.out.println("Got context");

      // Get a reference to the Bean
      Object ref = jndiContext.lookup("MyBeanName");
      System.out.println("Got reference");

      // Get a reference from this to the Bean's Home interface
      MyBeanHome home = (MyBeanHome) PortableRemoteObject.narrow (ref, MyBeanHome.class);

      // Create the object from the Home interface
      MyBean mybean = home.create();

      // call the methods to the Remote Interface
      System.out.println(mybean.functioncall());
      }
      catch(Exception e)
      {
      System.out.println(e.toString());
      }

      If you want to externalize the properties anyway, and Tomcat does'nt cooperate, try this hack. With this, you can place the properties files outside the code too:

      Properties props = new Properties();
      props.load( servlet.getServletContext().getResourceAsStream(
      "/WEB-INF/classes/jndi.properties" ) );
      InitialContext ctx = new InitialContext( props );
      ...

      Good luck.
      Masroor