- This topic has 15 replies, 4 voices, and was last updated 16 years, 2 months ago by Jeyanthi Thangiah.
-
AuthorPosts
-
eyalmMemberHi,
I’m using myEclipse 4.0.0 with eclipse 3.1.0
I’m using Jboss 3.2.7 within the ide ant start it .
I want to test my EJB that i build .
I wrote a simple java client that suppose to connect to the EJB and I get
” Hello not bound “.my EJB object is is called ‘Hello’ and it is in packege ejbHere is my full project structrue: HelloEJB/src/ejb/HelloBean .I run xdoclet
and then , deploy the Ejb. so far everything seems ok ,
i checked that the jboss really deloys the ‘ Hello.ear ‘ .The problem occures when i run the client application which it’s code is follows:
public static void main(String[] args) {
// TODO Auto-generated method stubHelloBean hb;
HelloHome home;
Hello h=null;
try {Context ctx = new InitialContext();
System.out.println(“after InitialContext “);
Object objref=ctx.lookup(JNDI_NAME);
PortableRemoteObject pro=new PortableRemoteObject();
home=(HelloHome)pro.narrow(objref,HelloHome.class);
try {h=home.create();
h.printHello();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CreateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}when i run this code , and get to the line ‘ Object objref=ctx.lookup(JNDI_NAME);’
i get this message : Hello not bound .Any ideas ?
Thanks.
Riyad KallaMemberI am asking someone to look into this.
GregMemberWhat is the value of JNDI_NAME? Can you post your source for the HelloBean EJB class?
eyalmMemberHi ,
here is my full client code :
import java.rmi.RemoteException;
import java.util.Properties;import javax.ejb.CreateException;
import javax.naming.*;
import javax.rmi.*;import com.sun.corba.se.impl.javax.rmi.PortableRemoteObject;
import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;import ejb.Hello;
import ejb.HelloBean;
import ejb.HelloHome;public class myHelloWorldClient {
/**
* @param args
*
*
*
*///public static final String COMP_NAME=”java:comp/env/ejb/HelloWorld”;
//public static final String JNDI_NAME=”ejb/HelloWorld”;public static final String COMP_NAME=”java:comp/env”;
//public static final String COMP_NAME=”java:comp”;// public static final String JNDI_NAME=”Hello”;
public static final String JNDI_NAME=”ejb/Hello”;
public static void main(String[] args) {
// TODO Auto-generated method stubHelloBean hb;
HelloHome home;
Hello h=null;
try {Context ctx = new InitialContext();
System.out.println(“after InitialContext “);
Object objref=ctx.lookup(JNDI_NAME);
PortableRemoteObject pro=new PortableRemoteObject();
home=(HelloHome)pro.narrow(objref,HelloHome.class);
try {h=home.create();
h.printHello();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CreateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
}
and here is my EJB class code :
package ejb;import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;/**
* XDoclet-based session bean. The class must be declared
* public according to the EJB specification.
*
* To generate the EJB related files to this EJB:
* – Add Standard EJB module to XDoclet project properties
* – Customize XDoclet configuration for your appserver
* – Run XDoclet
*
* Below are the xdoclet-related tags needed for this EJB.
*
* @ejb.bean name=”Hello”
* display-name=”ejb/Hello”
* description=”Description for Hello”
* jndi-name=”ejb/Hello”
* type=”Stateless”
* view-type=”remote”
*/
public class HelloBean implements SessionBean {/** The session context */
private SessionContext context;public HelloBean() {
super();
// TODO Auto-generated constructor stub
}/**
* Set the associated session context. The container calls this method
* after the instance creation.
*
* The enterprise bean instance should store the reference to the context
* object in an instance variable.
*
* This method is called with no transaction context.
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void setSessionContext(SessionContext newContext)
throws EJBException {
context = newContext;
}public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub}
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub}
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub}
/**
* An example business method
*
* @ejb.interface-method view-type = “remote”
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void printHello() throws EJBException {
System.out.println(“Hello !!!”);
}
/**
* An example business method
*
* @ejb.interface-method view-type = “remote”
*
*/
public void name() {
System.out.println(“EJB Statless “);
}}
GregMemberYour JNDI name that you define in the XDoclet tags in your EJB source code is called
* jndi-name="ejb/Hello"
. However, in your client code the JNDI_NAME constant uses “ejb/HelloWorld”. You will need to make these 2 the same. The easiest should be to just make the JNDI_NAME constant in your client “ejb/Hello”. If you change your XDoclet jndi-name tag, you will need to re-run XDoclet generation to get the new interfaces and xml files with the update jndi-name.
eyalmMemberHi Greg ,
Thanks for the quick answers .
I affraid that there is a misunderstanding : if you look into the client code,
you’ll see that the jndi-name is correct ( there are some other lines which refer to
jndi-name , but they are all remarked ) the correct one is with the name “ejb/Hello”but still, when I run the client it gives me the same message “Hello not bound ”
any idea ?
Thanks.
GregMemberDid you add the jboss subtask and specify “version” and “destDir” attributes in your XDoclet EJB configuration? If you did, make sure that the <jndi-name> tag for your Hello session bean was generated correctly in your jboss.xml file.
eyalmMemberHi Greg ,
I didn’t add the the jboss subtask , so i didn’t have the jboss.xml file in the right
directory.After I configure the xdoclet again as in the Help manual
and running xdoclet again I see that there is a new file for jboss ( jboss.xml ) under
“C:\jboss\jboss-3.2.7\server\default\deploy ” ( as I configure it )After redeploy the application , I moved that file to :
“C:\jboss\jboss-3.2.7\server\default\deploy\Hello.ear\HelloEJB.jar\META-INF ” .Is it the right place ?
Now , after doing it , when I run the client , I get a new message when getting to
the line : Object objref=ctx.lookup(JNDI_NAME);
:
“javax.naming.NoInitialContextException: Need to specify class name in environment or system property …”I checked wether the names are o.k ( as you suggested ) and everything .it all seems fine
What’s wrong ??
GregMemberFor JBoss, you have to provide a jndi.properties file in your client application.
So create a jndi.properties file that contains the following:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=jnp://localhost:1099 java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Now this file will specify the class name for the initial context factory.
A google search of “jndi.properties jboss” brings up lots of helpful links, including this one:
http://www.huihoo.com/jboss/online_manual/3.0/ch01s15.html
eyalmMemberit seems like never ending story :
I created a new property file ( which called “jndi.properties”) put it under the classpath.
now , when I run the client I get :
“Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory ] ”please help !
Riyad KallaMembereyalm,
That class should be in the jbossall-client.jar or jnp-client.jar in the JBoss directory, you can forcefully add this to your classpath by navigating to Window > Prefs > MyEclipse > App Servers > JBoss 3 > Paths, click “Add” next to Append to Classpath, and find that JAR and add it.
eyalmMemberHi
I think I’m lost . I did as you told me : I added the 2 (!) jars which contain the NamingContextFactory.class , I even opened ( with WinRar ) these jar files to make sure that they really
contain that class , and indeed they are . I added them to the classpath of jboss ( as you instructed me ) ,and again
the same message: ” Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory ] ”than , I added those jar to the run classpath ( via Run->Run..->classpath tab) and again
the same message.any idea ?
eyalmMemberContinue from last message ..
I tried another way to overcome the problem :
instead of using the property file I used it in the code , i.e
“Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
“org.jnp.interfaces.NamingContextFactory”);p.put(Context.PROVIDER_URL,”jnp;//localhost:1099″);
p.put(Context.URL_PKG_PREFIXES,”org.jboss.naming:org.jnp.interfaces”);Context ctx = new InitialContext(p);
…
..”
now, it doesn’t throw the ClassNotFoundException any more , BUT ,
there is a new message when I get to “lookup” line :“Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@9173ef”
??
Riyad KallaMembereyalm,
Please email me a sample project that exhibits this problem to support@genuitec.com ATTN Riyad, I will try and solve this problem locally.
eyalmMemberI sent you a winrar file which includes all the project files.
Thanks. -
AuthorPosts