ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory
<p>Environment used:</p>

<ul>
<li>WildFly 9.0.2.Final</li>
<li>EJB 3.0</li>
<li>Ant</li>
<li>Eclipse</li>
</ul>

<p><em>Test.jsp</em> is invoking <code>getDbConnection</code> method of <em>Test.java</em> class.</p>

<p>Test.jsp</p>

<pre><code>&lt;%@page import="com.testmodule.pojo.Test"%&gt;
&lt;%
    try{
        System.out.println(" Going to call getDbConnection method of 'Test' class. This 'Test' class shall be "
            + " part of testclient.jar. testclient.jar shall be deployed as a module --- module add --name=testclient --resources=/Downloads/lib/test/testclient.jar");
        System.out.println(" test.jsp shall be present in test.ear...'jboss-deployment-structure.xml' shall be present in "
            + " in META-INF directory of test.ear with entry as -- &lt;dependencies&gt;&lt;module name=\"testclient\" export=\"true\" /&gt; &lt;/dependencies&gt;");
        System.out.println(" Dont want to put 'jboss-client.jar' in Test.ear--&gt;Test.war--&gt;WEB-INF/lib , As there are multiple ear's which are accessing Test.java class");

        new Test().getDbConnection();
    } catch(Exception e) {
        e.printStackTrace();
    }
%&gt;
</code></pre>

<p>Test.java</p>

<pre><code>package com.testmodule.pojo;

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Test { 
    public void getDbConnection(){
        try {
            Properties jndiProps = new Properties();

            jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, 
                "org.jboss.naming.remote.client.InitialContextFactory");
            jndiProps.put(Context.PROVIDER_URL,"remote://29.86.30.73:4447");
            jndiProps.put(Context.SECURITY_PRINCIPAL, "testuser");
            jndiProps.put(Context.SECURITY_CREDENTIALS, "testpassword");
            jndiProps.put("jboss.naming.client.ejb.context", true);

            Context context = new InitialContext(jndiProps);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}
</code></pre>

<p>Following error occurred while accessing test.jsp.</p>

<pre><code>10:09:26,536 ERROR [stderr] (default task-1) javax.naming.NamingException: WFLYNAM0027: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "deployment.test.ear.test.war:main" from Service Module Loader [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory from [Module "deployment.test.ear.test.war:main" from Service Module Loader]]
10:09:26,537 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContext.getDefaultInitCtx(InitialContext.java:118)
10:09:26,537 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContext.init(InitialContext.java:99)
10:09:26,537 ERROR [stderr] (default task-1)    at javax.naming.ldap.InitialLdapContext.&lt;init&gt;(InitialLdapContext.java:154)
10:09:26,537 ERROR [stderr] (default task-1)    at org.jboss.as.naming.InitialContext.&lt;init&gt;(InitialContext.java:89)
10:09:26,548 ERROR [stderr] (default task-1) Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory from [Module "deployment.test.ear.test.war:main" from Service Module Loader]
10:09:26,548 ERROR [stderr] (default task-1)    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
10:09:26,548 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
10:09:26,549 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
10:09:26,549 ERROR [stderr] (default task-1)    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
</code></pre>

<p>I don't want to put <em>jboss-client.jar</em> in Test.ear --> Test.war --> WEB-INF/lib, as there are multiple EARs which will access <em>Test.java</em> class.</p>