JNDI Archive

JNDI lookup in JBoss

This post illustrates a simple JNDI lookup in Jboss Server that can be used to lookup Data Sources etc.

1. Open a command prompt and set the class path to the jbossall-client.jar file.

set classpath=%classpath%;G:\jboss-5.1.0.GA\client\jbossall-client.jar

2. Compile and execute the JNDITest.java program.

import java.security.Security;

import java.util.Properties;

import javax.naming.Context;

import javax.naming.InitialContext;

public class JNDITest


public static void main(String args[]) throws Exception


Properties env = new Properties();


env.setProperty(Context.PROVIDER_URL, "");

Context ctx = new InitialContext(env);

System.out.println("Created InitialContext, env=" + env);

Object data = ctx.lookup("jmx/invoker/RMIAdaptor");

System.out.println("lookup(jmx/invoker/RMIAdaptor): " + data);




Common errors occurring while JNDI lookup.

1. Exception in thread “main” javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.HttpNamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.HttpNamingContextFactory]

Solution:- Set the classpath to jbossall-client.jar file under $JBOSS_HOME/client.

Best Regards.

Securing the JNDI with Admin Role in 11g

We need to go to the server and access the link for the jndi. The jndi tree will show up in a new window.

Check the default roles and policies
By default, everyone has access to the JNDI

Remove the role

And then add the admin role. This will enable only the Admin user to have access to the JNDI

If we try to access the JNDI now without the Admin credentails, we get the following exceptions

javax.naming.NoPermissionException: User <anonymous> does not have permission on
StringJndiName to perform modify operation. [Root exception is javax.naming.NoP
ermissionException: User <anonymous> does not have permission on StringJndiName
to perform modify operation.]
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:234)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef