List jndi entries to debug JNDI lookup problems

What will you do if you have a problem with JNDI lookup? Maybe something you think should be there but a JNDI lookup throws NamingNotFoundException instead? I've seen people add the following debug code:
InitialContext ic = new InitialContext();
There is a better way of doing that, without adding these debugging statements. In GlassFish, you can use the command "asadmin list-jndi-entries":
C:\>%GLASSFISH_HOME%\bin\asadmin list-jndi-entries
Jndi Entries for server within root context:

foo.FooRemote: javax.naming.Referencecustom:
com.sun.enterprise.naming.TransientContextfoo.FooRemote__3_x_Internal_RemoteBusinessHome__: javax.naming.Reference
jdo: com.sun.enterprise.naming.TransientContext
mail: com.sun.enterprise.naming.TransientContext
foo.FooRemote#foo.FooRemote: javax.naming.Reference
jdbc: com.sun.enterprise.naming.TransientContext
UserTransaction: com.sun.enterprise.distributedtx.UserTransactionImpl
ejb: com.sun.enterprise.naming.TransientContext

Command list-jndi-entries executed successfully.
list-jndi-entries is not recursive and does not list the content of any subcontext. To drill down to a subcontext, specify a --context param:
C:\>%GLASSFISH_HOME%\bin\asadmin list-jndi-entries --context ejbmgmt:
Command list-jndi-entries executed successfully.

C:\>%GLASSFISH_HOME%\bin\asadmin list-jndi-entries --context ejb/mgmt
MEJB: org.glassfish.kernel.javaee.MEJBNamingObjectProxy

Command list-jndi-entries executed successfully.
What if you don't remember the exact command and subcommand? GlassFish can help you find what you mean, as long as you give it a hint. There is never a need to remember these asadmin subcommands in glassfish. For example, this is how I ran the above command:
C:\>%GLASSFISH_HOME%\bin\asadmin jndi
Closest matching command(s): create-jndi-resource
CLI001 Invalid Command, jndi.

C:\>%GLASSFISH_HOME%\bin\asadmin list-jndi-entries


Anonymous said...

Thank you, that little bit of information has really helped me

Anonymous said...

Thank you Thank you
Thank you Thank you
Thank you Thank you

I was about to give up!!!


Anna said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Vũ Diệu Linh said...

I enjoyed on reading your blog post. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. Please visit my website, Friv 4000 Games is where all the free friv games.
Friv 4000