• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoInitialContextException

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I deploy a bean successfully, but when I run the client program it was
giving the runtime exception like
javax.naming.NoInitialContextException: Need to specify class name in
environmen or system property,or as an applet parameter, or in an
application resource file: java.naming.factory.initial
Client source code:
package test;
import javax.naming.InitialContext;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
public class Main
{
public static void main(String[] args)
{
try
{
// Get a naming context
InitialContext jndiContext = new InitialContext();
System.out.println("Got context");
// Get a reference to the Interest Bean
Object ref = jndiContext.lookup("First");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home interface
TestHome home = (TestHome)
PortableRemoteObject.narrow(ref, TestHome.class);
// Create an Interest object from the Home interface
TestRemote call = home.create();
System.out.println("Process strat");
String msg = call.process();
System.out.println(msg);
System.out.println("Process end");
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
I am not understanding that exception any one can help me.
Thanks,

Sharief
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess it is because you havent passed Properties (The jndi implementation class etc)to InitialContext contructor.
 
Ahamed Sharif
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
But I dont know how to pass jndi properties class because i am new to ejb,
so please could u show me how to write and pass the jndi properties class.
Thanks,
Sharief
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
this is a simple code,
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
//props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");
props.put(Context.PROVIDER_URL, "localhost:1099");
InitialContext context=new InitialContext(props);
Set the properties value according to your application server,I'm using the jboss that's why the above values are set in my properties object,so make sure these values should match to your application server jndi properties.
Regards,
Nauman
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using same code for InitialContext as Nauman said as follows-
Weblogic as Application server and tomcat as web server.
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001");
InitialContext initCtx = new InitialContext(p);
Object obj = initCtx.lookup("myFacilityService");
FacilityServiceHome home = (FacilityServiceHome)PortableRemoteObject.narrow(obj,
FacilityServiceHome.class);
//Create the remote interface instance
FacilityService cli = home.create();
cli.getAllFacility();
httpServletRequest.setAttribute("FacilityList", cli.getAllFacility());

I have copied jar in Web-WEB-INF- lib and weblogic.jar in Tomacat-common-lib
getting error as follows
java.lang.NullPointerException
at weblogic.rmi.internal.StubGenerator.getStubOnClient(StubGenerator.java:694)
at weblogic.rmi.internal.StubGenerator.getStubClass(StubGenerator.java:666)
at weblogic.rmi.internal.StubGenerator.generateStub(StubGenerator.java:712)
at weblogic.rmi.internal.StubGenerator.generateStub(StubGenerator.java:699)
at weblogic.rmi.extensions.StubFactory.getStub(StubFactory.java:76)
at weblogic.jndi.WLInitialContextFactoryDelegate.newRootNamingNodeStub(WLInitialContextFactoryDelegate.java:486)
at weblogic.jndi.WLInitialContextFactoryDelegate.newRemoteContext(WLInitialContextFactoryDelegate.java:449)
at weblogic.jndi.WLInitialContextFactoryDelegate.newContext(WLInitialContextFactoryDelegate.java:345)
at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:308)
at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:234)
at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:135)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:250)
at javax.naming.InitialContext.init(InitialContext.java:226)
at javax.naming.InitialContext.(InitialContext.java:202)
at com.powermanage.mcaccess.portal.AnnotationAction.execute(AnnotationAction.java:73)
 
Ahamed Sharif
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I set the properties but still getting some errors,
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory. Root exception is java.lang.ClassNotFoundException:
org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:217)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.jav
a:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
49)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at test.Main.main(Main.java:37)
And I set the classpath for jboss-client.jar like
>set classpath=.;C:\jboss-3.0.8_tomcat-4.1.24\client\jboss-client.j
ar;%classpath%
and the jndi.properties in C:\jboss-3.0.8_tomcat-4.1.24\server\cinfig\conf
so i set the classpath for that also.
jndi.propeerties files looklike this,
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces
# Do NOT uncomment this line as it causes in VM calls to go over
# RMI!
#java.naming.provider.url=localhost

and The client code is,

package test;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.ejb.CreateException;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import javax.naming.*;
import test.TestRemote;
import test.TestHome;
public class Main
{
/** This method does all the work. It creates an instance of the Interest EJB on
the EJB server, and calls its `calculateCompoundInterest()' method, then prints
the result of the calculation.
*/
public static void main(String[] args)
{

try
{
// Get a naming context
/* InitialContext jndiContext = new InitialContext();
System.out.println("Got context");*/

Properties props = new Properties();
props.putContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingC
ontextFactory");
//props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming
rg.jnp.interfaces");
props.put(Context.PROVIDER_URL, "localhost:1099");
InitialContext context=new InitialContext(props);

// Get a reference to the Interest Bean
Object ref = context.lookup("First");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home interface
TestHome home = (TestHome)
PortableRemoteObject.narrow(ref, TestHome.class);
// Create an Interest object from the Home interface
TestRemote call = home.create();
System.out.println("Process strat");
String msg = call.process();
System.out.println(msg);
System.out.println("Process end");
}
catch(java.rmi.RemoteException re)
{
re.printStackTrace();
}
catch(Throwable t)
{
t.printStackTrace();
}
}
}

Help would be so appriciate,
Thanks,
Sharief
 
Nauman Khan
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ahmed,
I'm not sure which application server you are using right now,you have to set the classpath with the following jar files if you are using jboss.

.;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\htmlconverter.jar;%JBOSS_HOME%\client\jboss-j2ee.jar;%JBOSS_HOME%\client\jbossall-client.jar;%JBOSS_HOME%\client\log4j.jar;%JBOSS_HOME%\client\jnp-client.jar;%JBOSS_HOME%\client\jboss-client.jar;%JBOSS_HOME%\client\jnet.jar;%JBOSS_HOME%\client\jboss-iiop-client.jar;%JBOSS_HOME%\client\jboss-common-client.jar
Hope this could help.
Regards,
Nauman
 
Ahamed Sharif
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks succefully i got the results, and i am using jboss3.0.8+tomcat4.24
Khuda hafiz,
Sharief
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic