Ejb lookup from StandAlone/Tomcat to Jboss5+

Hi,

Lately I was trying to do EJB lookup from my Web Application (Tomcat 6) to my Jboss project(Jboss5.1)

That should be pretty simple but without the right jars it just wont work.

So:

1. Take all jars from the client dir of jboss (Jboss_home_dir/Client/) and put them under the Lib dir of your web project which deployed under tomcat.

2. The client code which does the EJB look up will look like that:


private void ejbCall() throws NamingException
	{

		Properties p = new Properties();
		p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
		p.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
		p.put(Context.PROVIDER_URL, "jnp://remote.server.ip:1099");
		InitialContext context = new InitialContext(p);
		String lookupStr = "jndi-remote-lookup-string";
		DispactherBeanRemote dispactherBean = (DispactherBeanRemote) context.lookup(lookupStr);
		MomDispatcherResponseMsgDTO momDispatcherResponseMsgDTO =  dispactherBean.dispatchMsg();
		System.out.println("dispactherBean ="+ momDispatcherResponseMsgDTO.toString());
	}

Again, dont forget to add all the jars from the jboss client. Else you will get lots of weird exceptions,

[ad]

Idan.

Related Articles:

(1400)

Define jboss logs in the application level.

Hi,
The next post will demonstrate how to define jboss logs for a specific application
in a way that it will write all it’s logs to an independent log file.

(tested on Jboss5.1 AS)

Under jboss-dir/conf we have file named: jboss-log4j.xml

1. let’s add new appender:

  
     
     
     
     
     

     
       
     
   

2. let’s add category:

   
     < priority value="debug" />
     < appender-ref ref="projectName" />
   

Now on each class we want to use the Logger(which is imported from org.apache.log4j.Logger) we need to use it this way:

public class Someclass

      private final static Logger logger = Logger.getLogger(Someclass.class);
      public dispatchMsg()
      {
         logger.debug("My first log msg");
      }
}

Idan.

[ad]

Related Articles:

(1400)