• Post Reply Bookmark Topic Watch Topic
  • New Topic

A small EJB problem in the NamingContextFactory  RSS feed

Narendran Nair
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Every one

I started to use JBoss from last week onwards and i was successful enough to deploy my first Session Bean in the JBoss4 Server with out any errors. But when i tried to write the client application, i was not successful as the deployment. the file compiles correctly withone any warnings and errors but when i try to run the application it gives a small error.

First let me tell abt the bean i wrote . it is a small bean that returns a string value and it is similar to the normal HelloWorld applications. The deployed jar has got the 3 needed class files and the ejb-jar.xml file.

The client program compiles fine and here it is ....

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class HelloWorldClient {
public static void main(String args[]){
Hashtable env = new Hashtable();
//env.put("java.naming.factory.url.pkgs","org.jboss.naming rg.jnp.interfaces");
Context ctx = new InitialContext(env);
Object obj = ctx.lookup("HelloWorld");
HelloWorldHome home = (HelloWorldHome) javax.rmi.PortableRemoteObject.narrow(obj,HelloWorldHome.class);
HelloWorld helloWorld = home.create();
}catch(Exception ex){

when i tried to run the above program it gives this message and exits

Cannot instantiate class: org.jnp.interfaces.NamingContextFactory

Can any one help me in this ...
i am using Jboss4 and J2SE1.4

thanking you in advance..

Tony Walters
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'm having the same problem. Despite jnp-client.jar being in the classpath, running the client causes the same error due to a ClassNotFoundException for org.jnp.interfaces.NamingContextFactory.

Here is the Client:

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;

import steel.services.*;
import steel.util.*;
import steel.domain.*;

public class Client {
public static void main(String [] args) {
try {
Properties props = new Properties();
props.setProperty("java.naming.provider.url", "jnp://");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
Context context = new InitialContext(props);
Object obj = context.lookup("BioServices");
BioServicesHome home = (BioServicesHome)PortableRemoteObject.narrow(obj, BioServicesHome.class);
BioServices service = home.create();
BioDTO bio = new BioDTO();
Integer id = service.createBio(bio);
} catch(Exception e) {

Here is the output:

Buildfile: build.xml


[delete] Deleting directory C:\projects\steel-test\tmp

[mkdir] Created dir: C:\projects\steel-test\tmp

[javac] Compiling 1 source file to C:\projects\steel-test\tmp

[java] javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
[java] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:652)
[java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
[java] at javax.naming.InitialContext.init(InitialContext.java:219)
[java] at javax.naming.InitialContext.<init>(InitialContext.java:195)
[java] at Client.main(Client.java:19)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:324)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:196)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:133)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:661)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:168)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:77)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
[java] at org.apache.tools.ant.Task.perform(Task.java:364)
[java] at org.apache.tools.ant.Target.execute(Target.java:301)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:328)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1215)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1063)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:632)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:183)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)
[java] Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
[java] at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1150)
[java] at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1091)
[java] at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:967)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
[java] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
[java] at java.lang.Class.forName0(Native Method)
[java] at java.lang.Class.forName(Class.java:219)
[java] at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
[java] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)
[java] ... 23 more

Total time: 4 seconds

Here is the build file:

<target name="setProps">
<property name="base.dir" value="." />
<property name="src" value="${base.dir}/src" />
<property name="lib" value="${base.dir}/lib" />
<property name="build" value="${base.dir}/tmp" />
<property name="jboss.home" value="C:/jboss-3.2.1" />
<path id="jndiProps.path">
<fileset file="${lib}/jndi.properties" />
<path id="jbossClient.path">
<fileset dir="${jboss.home}/client">
<include name="*.jar"/>
<property name="j2ee.dir" value="D:/j2ee1.4" />
<path id="j2ee.path">
<fileset file="${j2ee.dir}/lib/j2ee.jar" />
<path id="lib.path">
<fileset dir="${lib}">
<include name="*.jar"/>
<path id="build.path">
<fileset dir="${build}">
<include name="Client.class"/>
<path id="full.path">
<path refid="j2ee.path" />
<path refid="lib.path" />
<path refid="jbossClient.path" />
<path refid="jndiProps.path" />
<target name="clean" depends="setProps">
<delete dir="${build}" />
<target name="prepare" depends="clean">
<mkdir dir="${build}" />
<target name="compile" depends="prepare">
<javac destdir="${build}" debug="true" deprecation="true">
<src location="${src}" />
<classpath refid="full.path" />
<target name="run" depends="compile">
<java classname="Client">
<pathelement path="full.path" />
<pathelement location="${build}" />

Been trying to figure this one out all day. Any suggestions?
Narendran Nair
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi man

i got that thing worked out .. i just put the content of %JBOSS_HOME%/client in the class path of the client program
i am using JBoss4 ... and i have read in some Blogs that you only need to add only 5 jars in the classpath .. currently i dont have the names of those files ...

and one thing also ...
in %JBOSS_HOME%/<default-config>/conf/jndi.properties
you can put props.setProperty things in that file ... must take a bakup of the orginal file ...

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!