2

I'm using JSPs and WildFly 9.0.2.Final with the following conditions:

  1. A JSP file (test.jsp) is accessing Test.java file.

  2. Test.java file is part of testclient.jar and has been deployed as a module.

  3. test.jsp file is part of Test.ear and has been deployed successfully but following error occurred while accessing the Test.java file from test.jsp:

    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)
    

These are the contents of test.jsp file present in test.ear:

<%@page import="com.testmodule.pojo.Test"%>
<% 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 -- <dependencies><module name=\"testclient\" export=\"true\" /> </dependencies>");
    new Test().getDbConnection();
} catch(Exception e){
    e.printStackTrace();
} %>

And these are the contents of Test.java present in testclient.jar:

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){}
    }
}
nochkin
  • 692
  • 6
  • 17
Kamal Vijay
  • 47
  • 1
  • 13
  • Acutally i dont want to put testclient.jar inside test.ear-->test.war-->WEB-INF-->lib. As there are also many other application which are accessing testclient.jar, if i go for this approach than i have to put testclient.jar in lib of each war archive... In jboss 5.x i usually put testclient.jar in $JBOSS_HOME/server/default/client directory, so that it can be accessed by each war archive.How to do this in wildfly9.0.2final. – Kamal Vijay Apr 01 '16 at 09:00

1 Answers1

1

I think you need to add a dependency to the module: javax.api.

Try to add

<dependencies>
    <module name="javax.api"/>
</dependencies>

to your module.xml

user140547
  • 7,750
  • 3
  • 28
  • 80