File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoInitialContextException:

 
Jatinder Singh
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i am trying to look up bean but getting exception as

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

for lookup i have written code as
jndiProp = new Properties();
jndiProp.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
jndiProp.put(Context.PROVIDER_URL, providerURL);

Context ctx = new InitialContext(jndiProp);
String ejbJndiName = ApplyLegacyProcessHome.JNDI_NAME;
Object obj = ctx.lookup(ejbJndiName);
but at ctx.lookup() i am getting exception.
Please help why this exception is coming
Thanks
Jatinder
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gurbinder,
I'm only guessing, but don't you also need to define the following properties as well:
  • Context.SECURITY_PRINCIPAL
  • Context.SECURITY_CREDENTIALS

  • Good Luck,
    Avi.
     
    Jatinder Singh
    Greenhorn
    Posts: 2
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Avi,

    Thanks avi i got the solution just added naming.jar, namingclient.jar, namingserver.jar files in classpath. Now its working fine.

    cheers
     
    Tuhin Ghosh
    Ranch Hand
    Posts: 33
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi M also getting same problem,

    ERROR :>

    Caught an unexpected exception!
    javax.naming.NoInitialContextException: Need to specify class name in environmen
    t or system property, or as an applet parameter, or in an application resource f
    ile: java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
    40)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
    )
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
    a:280)
    at javax.naming.InitialContext.lookup(InitialContext.java:347)
    at CurrconvClient.main(CurrconvClient.java:8)



    <CODE>

    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;

    public class CurrconvClient {
    public static void main(String[] args) {
    try {Context initial = new InitialContext();
    Object objref = initial.lookup("myconvert");

    CurrconvHome home = (CurrconvHome)PortableRemoteObject.narrow(objref,CurrconvHome.class);
    CurrconvRemote CurrencyConverter = home.create();
    double amount = CurrencyConverter.DollarstoRs(100.00);
    System.out.println(String.valueOf(amount));
    amount = CurrencyConverter.RstoDollars(100.00);
    System.out.println(String.valueOf(amount));
    }
    catch (Exception ex) {
    System.err.println("Caught an unexpected exception!");
    ex.printStackTrace();
    }}}
    Suggest me wat to do?

    THANKS
    tuhin

    [ October 31, 2006: Message edited by: Tuhin Ghosh ]
    [ October 31, 2006: Message edited by: Tuhin Ghosh ]
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic