title: WildFly Error while running application --java.lang.ClassNotFoundException: javax.naming.InitialContext
body: <p>I'm using JSPs and WildFly 9.0.2.Final with the following conditions:</p>
  
  <ol>
  <li><p>A JSP file (<em>test.jsp</em>) is accessing <em>Test.java</em> file.</p></li>
  <li><p><em>Test.java</em> file is part of <em>testclient.jar</em> and has been deployed as a module.</p></li>
  <li><p><em>test.jsp</em> file is part of <em>Test.ear</em> and has been deployed successfully but following error occurred while accessing the <em>Test.java</em> file from test.jsp:</p>
  
  <pre><code>09:50:35,036 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /test/test.jsp: javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/naming/InitialContext
  at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
  at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:777)
  at org.apache.jsp.test_jsp._jspService(test_jsp.java:70)
  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69)
  Caused by: java.lang.NoClassDefFoundError: javax/naming/InitialContext
  at com.testmodule.pojo.Test.getDbConnection(Test.java:12)
  at org.apache.jsp.test_jsp._jspService(test_jsp.java:58)
  ... 34 more
  Caused by: java.lang.ClassNotFoundException: javax.naming.InitialContext from [Module "testclient:main" from local module loader @707f7052 (finder: local module finder @11028347 (roots: /wildfly-9.0.2.Final/modules,/wildfly-9.0.2.Final/modules/system/layers/base))]
  at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
  </code></pre></li>
  </ol>
  
  <p>These are the contents of <em>test.jsp</em> file present in <em>test.ear</em>:</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("This file 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;");
      new Test().getDbConnection();
  } catch(Exception e){
      e.printStackTrace();
  } %&gt;
  </code></pre>
  
  <p>And these are the contents of <em>Test.java</em> present in <em>testclient.jar</em>:</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{
              Context context = new InitialContext(new Properties());
          } catch(Exception e){}
      }
  }
  </code></pre>