Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JBoss/WildFly and the fly likes JNDI/JBOSS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "JNDI/JBOSS" Watch "JNDI/JBOSS" New topic
Author

JNDI/JBOSS

Carlos A. Perez
Greenhorn

Joined: Apr 09, 2004
Posts: 27
Hi everyone:

im triying to connect to JNDI from a standalone app, i start sucessfully JBOSS and use the environment properties as indicated in JBOSS doc but it sends an javax.naming.NoInitialContextException

I dont know why it sends the exception, is it something about security in jboss (this is not an EJB) or the parameters are wrong in the JBoss doc?

this is the code:

public class ConnectJNDI {

public static void main (String[] args) {
Hashtable env = new Hashtable ();
env.put (Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
env.put (Context.PROVIDER_URL, "jnp://localhost:1099");
env.put (Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");
//env.put (Context.)
try {
InitialContext initCtx = new InitialContext( env );
initCtx.bind("x", new Object ());
} catch (NamingException e) {
System.out.println ( "PROBLEMS exception: " + e.getClass().getName() + " \nMessage: " + e.getMessage() );
e.printStackTrace();
}
}
}

an the stack is:

PROBLEMS exception: javax.naming.NoInitialContextException
Message: Cannot instantiate class: org.jboss.naming.NamingContextFactory
javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at jndi.ConnectJNDI.main(ConnectJNDI.java:28)
Caused by: java.lang.ClassNotFoundException: org.jboss.naming.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
... 4 more
Sean Stidman
Greenhorn

Joined: Jan 22, 2005
Posts: 2
Hi Carlos,

I believe your problem is here:

exception is java.lang.ClassNotFoundException: org.jboss.naming.NamingContextFactory


You need to make sure the class "org.jboss.naming.NamingContextFactory" is in the CLASSPATH of your client application. I don't have immediate access to JBoss, but I believe you'll likely find that class inside the "jboss.jar" file. If not, check the other JARs that are distributed with JBoss; one of them will have the class you need.
 
jQuery in Action, 2nd edition
 
subject: JNDI/JBOSS