NoInitialContextException + view JNDI tree (weblogic environment)

Discussion in 'Java' started by David Shen, Jul 22, 2003.

  1. David Shen

    David Shen Guest

    I have 2 questions regarding the weblogic.
    In a nutshell, here is my question.
    I encounter NoInitialContextException and need some suggestion.
    I would like to write code to view JNDI tree. Is it possible?
    (how should I do it?)

    1) question 1:

    I run the following code and receive the following error?
    Can you give me some suggestion?

    // code
    import javax.naming.InitialContext;
    import javax.naming.Context;
    import javax.naming.NamingException;
    import java.rmi.RemoteException;
    import java.util.*;

    public class Book {

    public static void main(String[] args) {

    Context ctx = null;
    Hashtable ht = new Hashtable();

    ht.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    ht.put(Context.PROVIDER_URL, "t3://127.0.0.1:7302");
    ht.put(Context.SECURITY_PRINCIPAL, "system");
    ht.put(Context.SECURITY_CREDENTIALS, "security");

    try {
    ctx = new InitialContext(ht);
    }
    catch (NamingException e) {
    e.printStackTrace();
    }
    finally {
    try {
    ctx.close();
    }
    catch (Exception e) {
    e.printStackTrace();
    }

    }
    }

    }


    // get the following exception
    javax.naming.NoInitialContextException: Cannot instantiate class:
    weblogic.jndi.WLInitialContextFactory. Root exception is
    java.lang.ClassNotFoundException:
    weblogic.jndi.WLInitialContextFactory
    at java.net.URLClassLoader$1.run (URLClassLoader.java:195) (pc
    69)
    at java.security.AccessController.doPrivileged(java.security.PrivilegedExceptionAction,java.security.AccessControlContext)
    (AccessController.java)
    at java.net.URLClassLoader.findClass (URLClassLoader.java:183) (pc
    13)
    at java.lang.ClassLoader.loadClass(java.lang.String,boolean)
    (ClassLoader.java:306) (pc 43)
    at sun.misc.Launcher$AppClassLoader.loadClass (Launcher.java:281) (pc
    36)
    at java.lang.ClassLoader.loadClass(java.lang.String)
    (ClassLoader.java:262) (pc 3)
    at java.lang.Class.forName0 (Class.java)
    at java.lang.Class.forName(java.lang.String,boolean,java.lang.ClassLoader)
    (Class.java:190) (pc 32)
    at com.sun.naming.internal.VersionHelper12.loadClass(java.lang.String)
    (VersionHelper12.java:40) (pc 8)
    at javax.naming.spi.NamingManager.getInitialContext
    (NamingManager.java:647) (pc 48)
    at javax.naming.InitialContext.getDefaultInitCtx
    (InitialContext.java:241) (pc 12)
    at javax.naming.InitialContext.init (InitialContext.java:217) (pc
    21)
    at javax.naming.InitialContext.<init>(java.util.Hashtable)
    (InitialContext.java:193) (pc 33)
    at Book.main (Book.java:22) (pc
    51)
    java.lang.NullPointerException
    at Book.main (Book.java:30) (pc
    83)

    2) My goal for the above code is to view the JNDI tree

    e.g.

    javax
    jms
    QueueConnectionFactory
    com
    dstsystem
    JDBC


    Can you give me some suggestion on how to write code to view the JNDI
    tree in weblogic?


    I really appreciate your help

    David
    David Shen, Jul 22, 2003
    #1
    1. Advertising

  2. David Shen wrote:
    > I have 2 questions regarding the weblogic.
    > In a nutshell, here is my question.
    > I encounter NoInitialContextException and need some suggestion.
    > I would like to write code to view JNDI tree. Is it possible?
    > (how should I do it?)
    >
    > 1) question 1:
    >
    > I run the following code and receive the following error?
    > Can you give me some suggestion?
    >
    > // code


    [elided]

    > // get the following exception
    > javax.naming.NoInitialContextException: Cannot instantiate class:
    > weblogic.jndi.WLInitialContextFactory. Root exception is
    > java.lang.ClassNotFoundException:
    > weblogic.jndi.WLInitialContextFactory


    [etc.]

    The stack trace tells you exactly what you need to know: the
    InitialContextFactory implementation class you are trying to use was not
    found. Either you have the name of the class wrong, or it is not in the
    classpath.

    >
    > 2) My goal for the above code is to view the JNDI tree
    >
    > e.g.
    >
    > javax
    > jms
    > QueueConnectionFactory
    > com
    > dstsystem
    > JDBC
    >
    >
    > Can you give me some suggestion on how to write code to view the JNDI
    > tree in weblogic?


    The question is not specific to WebLogic. Presumably you would do this
    by obtaining an InitialContext for the root of the part of the tree you
    wish to examine, and then applying the list and/or listBinding methods
    judiciously. I say "presumably" because I have never tried to do that
    sort of thing myself.

    There are, by the way, a large number of existing JNDI browsers; see,
    for instance,

    http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=JNDI browser&btnG=Google Search



    John Bollinger
    John C. Bollinger, Jul 22, 2003
    #2
    1. Advertising

  3. David Shen

    Sudsy Guest

    David Shen wrote:
    > I have 2 questions regarding the weblogic.
    > In a nutshell, here is my question.

    <snip>
    > javax.naming.NoInitialContextException: Cannot instantiate class:
    > weblogic.jndi.WLInitialContextFactory. Root exception is
    > java.lang.ClassNotFoundException:
    > weblogic.jndi.WLInitialContextFactory


    Nothing wrong with your code, just a CLASSPATH difficulty. It can't
    find your weblogic.jar file.
    Sudsy, Jul 22, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike S
    Replies:
    0
    Views:
    22,985
    Mike S
    Sep 16, 2004
  2. Mick
    Replies:
    2
    Views:
    9,501
    Marcin Grunwald
    Feb 23, 2005
  3. Replies:
    0
    Views:
    2,676
  4. Replies:
    0
    Views:
    499
  5. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,091
Loading...

Share This Page