[jboss-user] [EJB/JBoss] - Re: Problem when trying to access an EJB bean in an Enterpri

jaikiran do-not-reply at jboss.com
Fri Nov 10 04:03:00 EST 2006


I tried it out on my setup and this is what worked for me:

application.xml inside helloworld.ear:

<?xml version="1.0" encoding="UTF-8"?>
  | <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd">
  | <application>
  |     
  | 
  | 	<module>
  | 			<java>
  | 			helloworld-appclient.jar
  | 			</java>
  | 	</module>
  | 
  | <module>
  | 			<ejb>
  | 			helloworld-ejb.jar
  | 			</ejb>
  | 	</module>
  | </application>

application-client.xml in the helloworld-appclient.jar:

  | <?xml version="1.0" encoding="UTF-8"?>
  | 
  | <!DOCTYPE application-client PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN' 
  | 'http://java.sun.com/dtd/application-client_1_3.dtd'>
  | 
  | <application-client>
  |   <display-name>My App Client</display-name>
  |   <ejb-ref>
  |     <ejb-ref-name>ejb/someEJB</ejb-ref-name>
  |     <ejb-ref-type>Session</ejb-ref-type>
  |     <home>com.helloworld.ejb.HelloWorldBeanRemoteHome</home>
  |     <remote>com.helloworld.ejb.HelloWorldBeanRemote</remote>
  |   </ejb-ref>
  |   
  | </application-client>

jboss-client.xml inside helloworld-appclient.jar:

  | <jboss-client>
  |    <jndi-name>SampleApplicationClient</jndi-name>
  | 
  |    <ejb-ref>
  |       <ejb-ref-name>ejb/someEJB</ejb-ref-name>
  |       <jndi-name>com.helloworld.ejb.HelloWorldBean</jndi-name>
  |    </ejb-ref>
  | 
  |    
  | 
  | </jboss-client>	

All these files are deployed on the server and here's the packaging hierarchy:

helloworld.ear
  |  |
  |  |-------------- META-INF
  |  |                      |---------- application.xml
  |  |
  |  |-------------- helloworld-appclient.jar
  |  |                      |
  |  |                      |----------- META-INF
  |  |                      |                  |
  |  |                      |                  |-------- application-client.xml
  |  |                      |                  |-------- jboss-client.xml
  |  |
  |  |------------- helloworld-ejb.jar
  |  |                       |
  |  |                       |----------- META-INF
  |  |                       |                 |
  |  |                       |                 |-------- ejb-jar.xml
  |  |                       |                 |-------- jboss.xml
  |          

Now here's the code which does the lookup:

package org.myapp;
  | 
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | import javax.rmi.PortableRemoteObject;
  | 
  | import com.helloworld.ejb.HelloWorldBeanRemoteHome;
  | 
  | public class MyAppClient {
  | 
  |     /**
  |      * @param args
  |      */
  |     public static void main(String[] args) {
  |        try {
  |            Context ctx = new InitialContext();
  |            Object beanHome = ctx.lookup("java:comp/env/ejb/someEJB");
  |            System.out.println("Bean home: " + beanHome);
  |            HelloWorldBeanRemoteHome home = (HelloWorldBeanRemoteHome) PortableRemoteObject.narrow(beanHome,HelloWorldBeanRemoteHome.class);
  |           
  |            System.out.println("Client successful");
  |            
  |         } catch (NamingException e) {
  |             // TODO Auto-generated catch block
  |             e.printStackTrace();
  |         }
  |     }
  | 
  | }
  | 

Finally, the jndi.properties file which needs to be in the classpath of this class which does the lookup:


  | java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
  | java.naming.provider.url=jnp://localhost:1099
  | java.naming.factory.url.pkgs=org.jboss.naming.client
  | j2ee.clientName=SampleApplicationClient

This worked without any issues.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3984822#3984822

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3984822



More information about the jboss-user mailing list