Uncaught exception (java.lang.NoClassDefFoundError: javax.naming.InitialCon

When I am trying to run the following code in Visual Age for Java.

Properties p = new Properties();

if (this.initialContext == null) {

try {

if (this.portNumber != null) {

String url =

"IIOP://" + this.hostName + ":" + this.portNumber + "/";

System.out.println("Using provider URL of: " + url);

p.put(javax.naming.Context.PROVIDER_URL, url);

}

p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,

"com.ibm.ejs.ns.jndi.CNInitialContextFactory");

this.initialContext = new InitialContext(p);

} catch (NamingException e) {

System.out.println("Exception Error-Initial Context");

}

}

This is giving an error as follows at line

this.initialContext = new InitialContext(p);

Could you please explain me how can get rid of this error... I am running the code on local machine in websphere test environment.

ERROR:--

Uncaught exception (java.lang.NoClassDefFoundError: javax.naming.InitialContext)

Client_1.getInitialContext()

this=(TestEJBGroupEJBReserved.Client_1) TestEJBGroupEJBReserved.Client_1@5312

p=(java.util.Properties) {java.naming.factory.initial=com.ibm.ejs.ns.jndi.CNInitialContextFactory, java.naming.provider.url=IIOP://localhost:8080/}

Client_1.main(String [])

args=([Ljava.lang.String;) [Ljava.lang.String;@3ffb

c1=(TestEJBGroupEJBReserved.Client_1) TestEJBGroupEJBReserved.Client_1@5312

[1517 byte] By [rittu_kumar] at [2007-9-26 2:56:36]
# 1
Copy jndi.jar to jre/lib/ext or add its current location to the classpath on the local machine on which you are running the code.
surtee at 2007-6-29 10:47:53 > top of Java-index,Archived Forums,Java Programming...
# 2

Hope ur problem is in Visual Age settings for ur class.Basically it is not able to get com.ibm.ejs.ns.jndi.CNInitialContextFactory.For that do the foll steps.

1. Right click on ur class which is having ur code and click properties.Then Compute Now in Project Path.If it is still showing error means go to the second step

2. Click on the Edit button in the Project Path and then include IBM Websphere Test Environment in the Project Path

It will work

Pramod

pramod_bs at 2007-6-29 10:47:53 > top of Java-index,Archived Forums,Java Programming...
# 3
You can try like this:Right clik on ur class, go to run menu option, click on check classpath, click on first edit button,selectall possible projects.Thats it.
chandhanu at 2007-6-29 10:47:53 > top of Java-index,Archived Forums,Java Programming...
# 4
HI I have also had same propblem and i have followed your steps. Its working fine.Tnx for your HelpRegds,Panneer
panneert at 2007-6-29 10:47:53 > top of Java-index,Archived Forums,Java Programming...