How to view the JNDI tree in WildFly

Dumping the JNDI tree in WildFly empowers developers to gain deeper insights into the application’s runtime environment, enabling them to identify potential conflicts, or misconfigurations that might affect the overall performance and stability. Furthermore, this process provides a valuable means of documentation, aiding in collaboration between development and operations teams.

Overview of the naming subsystem

The naming subsystem provides an overview of the local JNDI namespace. The Jakarta EE platform specification defines the following JNDI contexts:

  • java:comp – The namespace is scoped to the current component (i.e. EJB)
  • java:module – Scoped to the current module
  • java:app – Scoped to the current application
  • java:global – Scoped to the application server

In addition to the standard namespaces, WildFly also provides the following two global namespaces:

  • java:jboss
  • java:/

Please note that only entries within the java:jboss/exported context are accessible over remote JNDI. For web deployments java:comp is aliased to java:module, so EJB’s deployed in a war do not have their own comp namespace.

You can view the JNDI binding in two ways: from the CLI or from the Web admin interface

Using CLI

Connect. Then navigate to the naming subsystem and run the jndi-view command:

[disconnected /] connect

[standalone@localhost:9990 /] /subsystem=naming:jndi-view
{
    "outcome" => "success",
    "result" => {
        "java: contexts" => {
            "java:" => {
                "ConnectionFactory" => {
                    "class-name" => "org.hornetq.jms.client.HornetQJMSConnection
Factory",
                    "value" => "HornetQConnectionFactory [serverLocator=ServerLo
catorImpl [initialConnectors=[org-hornetq-core-remoting-impl-invm-InVMConnectorF
actory?server-id=0], discoveryGroupConfiguration=null], clientID=null, dupsOKBat
chSize=1048576, transactionBatchSize=1048576, readOnly=false]"
                },
. . . . .
}

If running in Domain mode, include the host name and the target server in your command. Example:

/host=master/server=server-one/subsystem=naming:jndi-view

Using the Web Admin Console

Just log in to the admin console and select the Runtime upper Tab. From there, click on the View button in the JNDI subsystem:

how to view the jndi tree in wildfly

Fetch the JNDI Programmatically

Finally, you can dump the JNDI Context of the application server using the javax.naming.NamingEnumeration Class. Here is a simple method which print recursively the JNDI tree under “java:jboss“:

public void discoverJndi(String path, Context context) throws Exception {
    try {
        NamingEnumeration<NameClassPair> list = context.list(path);
        while (list.hasMore()) {
            String name = list.next().getName();
            String child = path.equals("") ? name : path + "/" + name;
            System.out.println(child);
            discoverJndi(child, context);
        }
    } catch (Exception e) {}
}

Then, to explore under the JNDI “java:jboss” just use the above method as follows:

discoverJndi("java:jboss", new InitialContext());

Here is a sample output from WildFly Console:

11:33:59,050 INFO  [stdout] (default task-1) java:jboss/TransactionManager
11:33:59,051 INFO  [stdout] (default task-1) java:jboss/TransactionSynchronizationRegistry
11:33:59,051 INFO  [stdout] (default task-1) java:jboss/UserTransaction
11:33:59,052 INFO  [stdout] (default task-1) java:jboss/ee
11:33:59,052 INFO  [stdout] (default task-1) java:jboss/ee/concurrency
11:33:59,052 INFO  [stdout] (default task-1) java:jboss/ee/concurrency/scheduler
11:33:59,052 INFO  [stdout] (default task-1) java:jboss/ee/concurrency/scheduler/default
11:33:59,053 INFO  [stdout] (default task-1) java:jboss/ee/concurrency/factory
11:33:59,053 INFO  [stdout] (default task-1) java:jboss/ee/concurrency/factory/default
11:33:59,053 INFO  [stdout] (default task-1) java:jboss/ee/concurrency/executor
11:33:59,053 INFO  [stdout] (default task-1) java:jboss/ee/concurrency/executor/default
11:33:59,053 INFO  [stdout] (default task-1) java:jboss/ee/concurrency/context
11:33:59,054 INFO  [stdout] (default task-1) java:jboss/ee/concurrency/context/default
11:33:59,054 INFO  [stdout] (default task-1) java:jboss/infinispan
11:33:59,054 INFO  [stdout] (default task-1) java:jboss/infinispan/container
11:33:59,054 INFO  [stdout] (default task-1) java:jboss/infinispan/container/ejb
11:33:59,055 INFO  [stdout] (default task-1) java:jboss/infinispan/container/hibernate
11:33:59,055 INFO  [stdout] (default task-1) java:jboss/infinispan/container/server
11:33:59,055 INFO  [stdout] (default task-1) java:jboss/infinispan/container/web
11:33:59,055 INFO  [stdout] (default task-1) java:jboss/infinispan/configuration
11:33:59,056 INFO  [stdout] (default task-1) java:jboss/infinispan/configuration/web
11:33:59,056 INFO  [stdout] (default task-1) java:jboss/infinispan/configuration/web/default
11:33:59,056 INFO  [stdout] (default task-1) java:jboss/infinispan/configuration/web/dist
11:33:59,056 INFO  [stdout] (default task-1) java:jboss/infinispan/configuration/web/routing
11:33:59,057 INFO  [stdout] (default task-1) java:jboss/infinispan/configuration/ejb
11:33:59,057 INFO  [stdout] (default task-1) java:jboss/infinispan/configuration/ejb/client-mappings
11:33:59,057 INFO  [stdout] (default task-1) java:jboss/infinispan/configuration/ejb/persistent
11:33:59,057 INFO  [stdout] (default task-1) java:jboss/infinispan/configuration/ejb/transient
11:33:59,058 INFO  [stdout] (default task-1) java:jboss/datasources
11:33:59,058 INFO  [stdout] (default task-1) java:jboss/datasources/ExampleDS
11:33:59,058 INFO  [stdout] (default task-1) java:jboss/mail
11:33:59,074 INFO  [stdout] (default task-1) java:jboss/mail/Default
11:33:59,077 INFO  [stdout] (default task-1) java:jboss/clustering
11:33:59,077 INFO  [stdout] (default task-1) java:jboss/clustering/registry
11:33:59,077 INFO  [stdout] (default task-1) java:jboss/clustering/registry/web
11:33:59,078 INFO  [stdout] (default task-1) java:jboss/clustering/registry/web/default-server
11:33:59,078 INFO  [stdout] (default task-1) java:jboss/clustering/registry/ejb
11:33:59,078 INFO  [stdout] (default task-1) java:jboss/clustering/registry/ejb/http-remoting-connector
11:33:59,078 INFO  [stdout] (default task-1) java:jboss/clustering/dispatcher
11:33:59,079 INFO  [stdout] (default task-1) java:jboss/clustering/dispatcher/default
11:33:59,079 INFO  [stdout] (default task-1) java:jboss/clustering/dispatcher/ee
11:33:59,079 INFO  [stdout] (default task-1) java:jboss/clustering/dispatcher/ejb
11:33:59,079 INFO  [stdout] (default task-1) java:jboss/clustering/dispatcher/hibernate
11:33:59,079 INFO  [stdout] (default task-1) java:jboss/clustering/dispatcher/server
11:33:59,080 INFO  [stdout] (default task-1) java:jboss/clustering/dispatcher/web
11:33:59,080 INFO  [stdout] (default task-1) java:jboss/clustering/group
11:33:59,080 INFO  [stdout] (default task-1) java:jboss/clustering/group/default
11:33:59,080 INFO  [stdout] (default task-1) java:jboss/clustering/group/ee
11:33:59,081 INFO  [stdout] (default task-1) java:jboss/clustering/group/ejb
11:33:59,081 INFO  [stdout] (default task-1) java:jboss/clustering/group/hibernate
11:33:59,081 INFO  [stdout] (default task-1) java:jboss/clustering/group/server
11:33:59,081 INFO  [stdout] (default task-1) java:jboss/clustering/group/web
11:33:59,082 INFO  [stdout] (default task-1) java:jboss/jgroups
11:33:59,082 INFO  [stdout] (default task-1) java:jboss/jgroups/factory
11:33:59,082 INFO  [stdout] (default task-1) java:jboss/jgroups/factory/default
11:33:59,082 INFO  [stdout] (default task-1) java:jboss/jgroups/factory/ee
11:33:59,082 INFO  [stdout] (default task-1) java:jboss/jgroups/factory/udp
11:33:59,083 INFO  [stdout] (default task-1) java:jboss/jgroups/channel
11:33:59,083 INFO  [stdout] (default task-1) java:jboss/jgroups/channel/default
11:33:59,083 INFO  [stdout] (default task-1) java:jboss/jgroups/channel/ee

How to dump the JNDI tree with the JMX Console (JBoss 5)

If you are running JBoss 4/5 having a dump of the JNDI tree is quite easy. Open your JMX console:

http://localhost:8080/jmx-console

and look for the Service “JNDIView” (it’s under the object name jboss)

Now simply find the method “list”, click it:

how to dump the jndi tree

Conclusion

In conclusion, this article has provided a comprehensive guide on how to dump the JNDI tree in the WildFly application server. Understanding the JNDI tree and its contents is crucial for developers and administrators to diagnose and troubleshoot issues within their Java EE applications. By following the step-by-step instructions outlined in this article, readers can easily access and extract valuable information from the JNDI tree, such as the registered resources, beans, and other crucial components.

Found the article helpful? if so please follow us on Socials