This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JBoss/WildFly and the fly likes A small EJB problem in the NamingContextFactory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "A small EJB problem in the NamingContextFactory" Watch "A small EJB problem in the NamingContextFactory" New topic

A small EJB problem in the NamingContextFactory

Narendran Nair
Ranch Hand

Joined: Sep 25, 2003
Posts: 35
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..


Narendran J S<br />SCJP 1.4<br /><a href="" target="_blank" rel="nofollow"></a><br /><a href="" target="_blank" rel="nofollow"></a><br /><a href="" target="_blank" rel="nofollow"></a>
Tony Walters
Ranch Hand

Joined: Feb 13, 2003
Posts: 54
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.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(
[java] at javax.naming.InitialContext.getDefaultInitCtx(
[java] at javax.naming.InitialContext.init(
[java] at javax.naming.InitialContext.<init>(
[java] at Client.main(
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(
[java] at java.lang.reflect.Method.invoke(
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] at
[java] Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
[java] at
[java] at
[java] at
[java] at java.lang.ClassLoader.loadClass(
[java] at java.lang.ClassLoader.loadClassInternal(
[java] at java.lang.Class.forName0(Native Method)
[java] at java.lang.Class.forName(
[java] at com.sun.naming.internal.VersionHelper12.loadClass(
[java] at javax.naming.spi.NamingManager.getInitialContext(
[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}/" />
<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

Joined: Sep 25, 2003
Posts: 35
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/
you can put props.setProperty things in that file ... must take a bakup of the orginal file ...

GeeCON Prague 2014
subject: A small EJB problem in the NamingContextFactory