This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


Carlos A. Perez

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() );

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(
at javax.naming.InitialContext.getDefaultInitCtx(
at javax.naming.InitialContext.init(
at javax.naming.InitialContext.<init>(
at jndi.ConnectJNDI.main(
Caused by: java.lang.ClassNotFoundException: org.jboss.naming.NamingContextFactory
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at com.sun.naming.internal.VersionHelper12.loadClass(
at javax.naming.spi.NamingManager.getInitialContext(
... 4 more
Sean Stidman

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.
Have you checked out Aspose?
subject: JNDI/JBOSS
jQuery in Action, 3rd edition