Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to test my ejb in jboss

 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JBoss forum...
 
Jitendra Patel
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Bob Peterson
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic