aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Jboss AS 6 - How to find an EJB via JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Jboss AS 6 - How to find an EJB via JNDI" Watch "Jboss AS 6 - How to find an EJB via JNDI" New topic
Author

Jboss AS 6 - How to find an EJB via JNDI

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

I am trying out a simple EJB 2.1 HelloWorld using Jboss AS 6. I created an EJB jar file with the following structure:



I also created a client standalone java class to test the above ejb. I deployed the jar file using the Jboss 6 admin console under Applications > EJB2 jars and clicked on "Add new resource". When i add the jar file it gives me this message so i assume it was deployed correctly.



Now when i run the client i get this error:



Initially i thought that i had to configure the JNDI resource for which the client will use to connect to find the EJB on the application server. Is this not necessary? The example i am using is using the EJB name in the lookup statement. Here is the section of the client code for making the connection. :





And here is the ejb-jar.xml file



One thing i found interesting is that when i compiled the client class, it refused to compile unless it had a reference to the HelloHome class. To resolve this i had to add the ejb jar file to the classpath of the client class. Is this how it is supposed to work? i.e. the ejb jar file needs to be on the classpath of the client?

In terms of the jndi name used for the lookup, do i need to create a new name? In the above example, it looks the EJB name is used as a lookup.

Andrew Moko
Ranch Hand

Joined: Dec 16, 2011
Posts: 55
Why do you deploy the app as a jar?? Enterprise beans need be packaged as war/ ear files.

This is what i would do.

1. From the console, look out for your app on the list of all deployed apps.

2. Check the jndi tree and see if your bean has been successfully registered.

If the above two test pass, your issue will be resolved.

Also you may want to use ejb3. It's much simplier you won't need to have all the home/ remote interface declarations. You just have to deal with annotations.

Hope this helps.
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

I am currently going through a book about EJB 3.0. Part of the introduction to EBJ 3.0 is to introduce me to the 2.0 variant hence why i am trying out this example. I think it does make sense to at least get a small understanding of how they work even if i am not planning on using EJB2.

I had a look at the console for the list of deployed applications and i cant see my application on the EJB2.0 menu item. This i think means that the jar file has not deployed correctly. The Jboss logs do show that it was deployed (see 4th line below).



Is there anything that looks wrong in the structure i described above?
Andrew Moko
Ranch Hand

Joined: Dec 16, 2011
Posts: 55
How are you compiling your project?? Are you using maven, ant or which tool are you using to create the war/ ear files?? I havent worked with v6 but to deploy an application in jboss, you need to copy it on the deploy folder..
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Ok i managed to resolve it. I am using eclipse to compile and generate the jar file. It looks like i had the ejb-jar.xml file in the wrong place. It was supposed to be in the META-INF folder. I copied it from ext1/ejb21/ejb-jar.xml to /META-INF/ejb-jar.xml and jboss picked up the jar file.



I also made a small change to the xml file as there was a typo in the namespaces used.
I used HelloWorldEJB as the jndi name for the client and it finally worked.

Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Jboss AS 6 - How to find an EJB via JNDI