wood burning stoves*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "A small EJB problem in the NamingContextFactory" Watch "A small EJB problem in the NamingContextFactory" New topic
Author

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(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL,"localhost:1099");
//env.put("java.naming.factory.url.pkgs","org.jboss.naming rg.jnp.interfaces");
env.put("java.naming.factory.url.pkgs","org.jboss.naming");
try{
Context ctx = new InitialContext(env);
Object obj = ctx.lookup("HelloWorld");
HelloWorldHome home = (HelloWorldHome) javax.rmi.PortableRemoteObject.narrow(obj,HelloWorldHome.class);
HelloWorld helloWorld = home.create();
System.out.println(helloWorld.hello());
helloWorld.remove();
}catch(Exception ex){
System.out.println(ex.getMessage());
}
}
}
-------------------------------------------------------------------

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..

Regards
Narendran


Narendran J S<br />SCJP 1.4<br /><a href="http://narendranj.blogspot.com" target="_blank" rel="nofollow">http://narendranj.blogspot.com</a><br /><a href="http://narendranj.blogspot.com" target="_blank" rel="nofollow">http://techboom.blogspot.com</a><br /><a href="http://bookmarks-share.blogspot.com" target="_blank" rel="nofollow">http://bookmarks-share.blogspot.com</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.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.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "jnp://127.0.0.1:1099");
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();
bio.setFirstName("James");
bio.setLastName("Bond");
Integer id = service.createBio(bio);
System.out.println(id);
} catch(Exception e) {
e.printStackTrace();
}
}
}


Here is the output:

Buildfile: build.xml

setProps:

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

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

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

run:
[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

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

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/jndi.properties
you can put props.setProperty things in that file ... must take a bakup of the orginal file ...

regards
Narendran
 
wood burning stoves
 
subject: A small EJB problem in the NamingContextFactory