NoInitialContextException + view JNDI tree (weblogic environment)

D

David Shen

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
 
J

John C. Bollinger

David said:
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
(e-mail address removed)
 
S

Sudsy

David said:
I have 2 questions regarding the weblogic.
In a nutshell, here is my question.
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top