aspose file tools*
The moose likes JBoss/WildFly and the fly likes how to test my ejb in jboss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "how to test my ejb in jboss" Watch "how to test my ejb in jboss" New topic
Author

how to test my ejb in jboss

zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
hello every one
i wrote a simple cart session bean(Cart.class,CartHome.class,CartBean.class),packaged them into a jar file,and deployed it in the jboss2.4.4,now i want to test it.
according the tutorial in this website,i wrote a "CartTestClient.class" and a "jndi.properties"file,the "jndi.properties" as follow:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces

i set the classpath ENVIRONMENT VARIABLE to point to file:

..........F:\myjava\jboss\client\jndi.properties

go to the directory that contain the "CartTestClient.class",type:

java com.mansion.ejb.CartTestClient

the output is:

F:\myjava\jboss\client>java com.mansion.ejb.CartTestClient
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException:
org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.jav
a:45)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
52)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
)
at javax.naming.InitialContext.init(InitialContext.java:222)
at javax.naming.InitialContext.<init>(InitialContext.java:178)
at com.mansion.ejb.CartTestClient.main(CartTestClient.java:37)

my "jndi.properties" and "CartTestClient.class" are within the same directory.
my "CartTestClient.java" as follow:

package com.mansion.ejb;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
public class CartTestClient {
private CartHome cartHome = null;
public static void main(String[] args) {
try{
Context initial=new InitialContext();
Object objref=initial.lookup("tt");
CartHome home=(CartHome)PortableRemoteObject.narrow(objref,CartHome.class);
Cart shoppingCart=home.create("Duke","123");
...................
...................
...................

}catch(Exception e){
e.printStackTrace();
}
}
}

why? which one is wrong?"jndi.properties" or "CartTestClient.java"?

thanks for any helps!
Craig Demyanovich
Ranch Hand

Joined: Sep 25, 2000
Posts: 173
This is an admittedly quick response based on the fact that I noticed that your jndi.properties file is different from mine, which is taken right from the JBoss 2.4.4 installation. Here's my file:

Best of luck,
Craig
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
thanks
yes,my properties file is copied from the joss online manual:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces

and yours:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactoryjava.naming.provider.url=localhost:1099java.naming.factory.url.pkgs=org.jboss.naming

would you like to explain the difference in the meaning between them?
otherwise,are there any GUI tools for jboss config files?
thank you very much!
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
hi Craig:

i found that it seem like something wrong with the "org.jnp" package,what is it?and when i use it?
thanks
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
hello
i have modify my properties file:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming

but still throw the same error:

F:\myjava\jboss\client>java com.mansion.ejb.CartTestClient
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException:
org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.jav
a:45)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
52)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
)
at javax.naming.InitialContext.init(InitialContext.java:222)
at javax.naming.InitialContext.<init>(InitialContext.java:178)
at com.mansion.ejb.CartTestClient.main(CartTestClient.java:11)


why ?
thanks!
zb cong
Ranch Hand

Joined: Jan 14, 2002
Posts: 416
hello
i have modify my properties file:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming

but still throw the same error:

F:\myjava\jboss\client>java com.mansion.ejb.CartTestClient
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException:
org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.jav
a:45)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
52)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
)
at javax.naming.InitialContext.init(InitialContext.java:222)
at javax.naming.InitialContext.<init>(InitialContext.java:178)
at com.mansion.ejb.CartTestClient.main(CartTestClient.java:11)


why ?
thanks!
Craig Demyanovich
Ranch Hand

Joined: Sep 25, 2000
Posts: 173
I'm very, very sorry that I forgot to monitor this thread after having posted a reply.
Do you have jnp-client.jar (from JBOSS_HOME/client) on your classpath for both compilation and execution?
Apologies,
Craig
Arpan Penkar
Greenhorn

Joined: Dec 29, 2002
Posts: 2
My name is Arpan. I have recently started working on EJB. I am using the JBoss v2.4.4 server. I have deployed the EJB properly but I have had some problem in the client program which looks up the EJB in the server.
My Client Program:
------------------------------------------
package orderMgmt;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
public class client
{
public static void main (String arg[]){
try{
Properties prop = new Properties ();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
prop.put(Context.PROVIDER_URL, "loalhost:1099");
// The exception is occuring in the following Line...
Context context = new InitialContext (prop);
Object objRef = context.lookup("OrderManagement");
orderMgmt.OrderManagementHome home = (orderMgmt.OrderManagementHome)javax.rmi.PortableRemoteObject.narrow (objRef, orderMgmt.OrderManagementHome.class);
orderMgmt.OrderManagement orderManagement = home.create ();
orderManagement.placeOrder ("xyz","abc",100);
orderManagement.remove ();
System.out.println ("Order Placed.");
}catch(Exception e){
e.printStackTrace();
}
}
}
-------------------------------------------
The client is compiling properly....
I am using the following line at the command prompt to execute the prog:
F:\Arpan\EJB\Ex1>java -cp d:\JBoss-2.4.4_Tomcat-4.0.1\jboss\lib\ext\ejb.jar;f:\j2sdkee1.3.1\lib\j2ee.jar;f:\jdk1.3.1_07\lib\dt.jar;f:\jdk1.3.1_07lib\tools.jar;f:\javamail1.2\javamail-1.2\xerces.jar;.; orderMgmt.client
--------------------------------------------
I am encountering the following exception:
---------------------------------------------
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory.
Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
------------------------------------------
This problem has been boggling me for quite sometime. I do not have an ejb.jar file pesent in my JBoss lib dir. I had browsed the net to find some solution but to no avail.
Is there anybody who has a solution to this problem? Thanks in Advance....
Originally posted by zb cong:
hello every one
i wrote a simple cart session bean(Cart.class,CartHome.class,CartBean.class),packaged them into a jar file,and deployed it in the jboss2.4.4,now i want to test it.
according the tutorial in this website,i wrote a "CartTestClient.class" and a "jndi.properties"file,the "jndi.properties" as follow:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces

i set the classpath ENVIRONMENT VARIABLE to point to file:

..........F:\myjava\jboss\client\jndi.properties

go to the directory that contain the "CartTestClient.class",type:

java com.mansion.ejb.CartTestClient

the output is:

F:\myjava\jboss\client>java com.mansion.ejb.CartTestClient
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException:
org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.jav
a:45)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
52)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246
)
at javax.naming.InitialContext.init(InitialContext.java:222)
at javax.naming.InitialContext.<init>(InitialContext.java:178)
at com.mansion.ejb.CartTestClient.main(CartTestClient.java:37)

my "jndi.properties" and "CartTestClient.class" are within the same directory.
my "CartTestClient.java" as follow:

package com.mansion.ejb;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
public class CartTestClient {
private CartHome cartHome = null;
public static void main(String[] args) {
try{
Context initial=new InitialContext();
Object objref=initial.lookup("tt");
CartHome home=(CartHome)PortableRemoteObject.narrow(objref,CartHome.class);
Cart shoppingCart=home.create("Duke","123");
...................
...................
...................

}catch(Exception e){
e.printStackTrace();
}
}
}

why? which one is wrong?"jndi.properties" or "CartTestClient.java"?

thanks for any helps!
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Moving to JBoss forum...
Jitendra Patel
Greenhorn

Joined: Dec 09, 2003
Posts: 1
Hello all,
The simple solution to this problem is u must have jnp-client.jar in ur classpath both while compiling and executing client app.I faced this prob in past and i got the solution as above
bye all...


Jitendra Patel<br />Programmer/Analyst
Bob Peterson
Ranch Hand

Joined: Jul 30, 2004
Posts: 47
I'm trying to get EJBs working with JBoss for the first time as well and am having the same problem. I'm running JBoss 3.0.8 due to project requirements (don't ask me why it's not the latest cuz I dunno).

I am pretty sure I have the jnp-client.jar in the classpath for both compile and runtime. I'm getting the error running junit tests via ant in eclipse. Any other suggestions?

Thanks
James Walker
Greenhorn

Joined: Sep 06, 2004
Posts: 1
you need these files in classpath;

jnp-client.jar
jboss-common-client.jar
jboss-j2ee.jar
jboss-net-client.jar
jbossall-client.jar

[www.kevinboone.com/jboss_tut_1.html]
Yorck Zhou
Greenhorn

Joined: Jan 04, 2003
Posts: 22
I use JBoss-2.4.10 on Windows XP, and need only have the following 2 jars
set to the CLASSPATH to make the JNDI works:
%JBOSS_HOME%/client/jnp-client.jar
%JBOSS_HOME%/client/jboss-client.jar


----------------------------------<br />SCJP SCWCD<br />dive into EJB, drinking hot Java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to test my ejb in jboss
 
Similar Threads
Please help me to run a client
Exception in thread "main" javax.naming.NoInitialContextException:
NoInitialContextException
naming exception
Simple Hello example for JBOSS