I�m facing problems in running a simple Session bean example based on EJB 3.0 spec. For better understand, I have enumerated the following points:-
1.I have installed JBoss AS 4 with EJB support 2.I have set the environment variables (CLASSPATH, JBOSS_HOME etc) appropriately for the required JAR files. 3.Following are the source code files- //SimpleSession.java package beans;
public class SimpleSessionClient { public static void main(String[] args) throws Exception { InitialContext ctx = new InitialContext(); SimpleSession simpleSession = (SimpleSession) ctx.lookup(SimpleSession.class.getName()); for (int i = 0; i < args.length; i++) { String returnedString = simpleSession.getEchoString(args[i]); System.out.println("sent string: " + args[i] +", received string: " + returnedString); } } }
4.This is how I have compiled my code javac -d . client/*.java javac -d . beans/*.java
5.And, this is how I have created the ejb3 JAR file jar cf SimpleSessionApp.ejb3 beans\*.java
6.For deployment, I have copied the JAR file created in step 5 inside the %JBOSS_HOME%/server/all/deploy directory 7.Finally, I�m running the client as shown below: java -Djava.naming.factory.initial= org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs= org.jboss.naming rg.jnp.interfaces -Djava.naming.provider.url= localhost client.SimpleSessionClient Now is the time for all good men
But, unfortunately I�m getting the following run-time error Exception in thread "main" javax.naming.NameNotFoundException: beans.SimpleSession not bound
Can anybody pls let me know the cause with suggestions to recover from the errors.
It does not require you to have such an environment variable, but you do need a JAVA_HOME, but you already have that too, otherwise you wouldn't have the app server started.
Your problem is the lookup string you are using. You are getting using the className, which isn't how JBoss binds it in the JNDI tree.
I don't recall off the top of my head what that string is, something I try not to clog my brain with. Jaikiran will know it for sure.
I don't recall off the top of my head what that string is, something I try not to clog my brain with. Jaikiran will know it for sure.
For EJB3, by default, the jndi name is a based on the combination of ApplicationName/BeanImplementationClassName/local or ApplicationName/BeanImplementationClassName/remote.
For example, if the application is MyApp and the bean implementation class is org.myapp.ejb.SimpleSession and if you are doing a lookup of remote interface then the default jndi name would be MyApp/SimpleSession/remote
Nikhil Jain
Ranch Hand
Joined: May 15, 2005
Posts: 383
posted
0
I get the following error when I changed the JNDI name
javax.naming.NameNotFoundException: Remote not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:529) at org.jnp.server.NamingServer.getBinding(NamingServer.java:537) at org.jnp.server.NamingServer.getObject(NamingServer.java:543) at org.jnp.server.NamingServer.lookup(NamingServer.java:296) at org.jnp.server.NamingServer.lookup(NamingServer.java:270) at org.jnp.server.NamingServer.lookup(NamingServer.java:270) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) at sun.rmi.transport.Transport$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Unknown Source) at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source) at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source) at sun.rmi.server.UnicastRef.invoke(Unknown Source) at org.jnp.server.NamingServer_Stub.lookup(Unknown Source) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(Unknown Source) at com.webage.client.TestClient.runTest(TestClient.java:17) at com.webage.client.TestClient.main(TestClient.java:25)
Nikhil Jain
Ranch Hand
Joined: May 15, 2005
Posts: 383
posted
0
I am again iterating the steps which I have done to create ejb
1. I created a package com.webage.ejbs i. Created an Interface
package com.webage.ejbs; import javax.ejb.*;
@Remote public interface SimpleBean { public String sayHello(String name); }
ii. Create the class for implementing the interface
I changed the JNDI lookup name to firstebj3/SimpleBeanImpl
I got this name from jmx console.!!
I guess now the client is able to do the look up. Now I get error saying that..
java.lang.ClassCastException: org.jnp.interfaces.NamingContext at com.webage.client.TestClient.runTest(TestClient.java:21) at com.webage.client.TestClient.main(TestClient.java:29)
I guess, you are still using the wrong jndi name for the lookup. You mentioned, you used firstebj3/SimpleBeanImpl/Remote to do the lookup. Change it to:
Note, the lowercase 'r' in Remote. Give it a try.
vinay kumar gundu
Greenhorn
Joined: Mar 26, 2007
Posts: 5
posted
0
Give jndi name like this
code:
ctx.lookup("SimpleBeanImpl/remote");
it will work fine...
Nikhil Jain
Ranch Hand
Joined: May 15, 2005
Posts: 383
posted
0
Yups...it worked with ctx.lookup("firstebj3/SimpleBeanImpl/remote");
thanks...
Hemkiran Gadey
Greenhorn
Joined: Aug 29, 2005
Posts: 2
posted
0
Shashank,
Could you post the contents of your ejb-jar.xml?
thanks
Nikhil Jain
Ranch Hand
Joined: May 15, 2005
Posts: 383
posted
0
Hi,
There is no ejbjar.xml. ejb-jar.xml is not mandatory with Ejb3.0