• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JNDI/JBOSS

 
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic