运行 应用程序时出现 WildFly 错误 --java.lang.ClassNotFoundException: javax.naming.InitialContext
WildFly Error while running application --java.lang.ClassNotFoundException: javax.naming.InitialContext
我正在使用 JSPs 和 WildFly 9.0.2.Final,条件如下:
一个JSP文件(test.jsp)正在访问Test.java 文件.
Test.java 文件是 testclient.jar 的一部分,并且已部署为模块.
test.jsp 文件是 Test.ear 的一部分并且已成功部署但是从 test.jsp:
访问 Test.java 文件时出现以下错误
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)
这些是 test.jsp 文件的内容 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();
} %>
这些是 Test.java 的内容 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){}
}
}
我认为您需要向模块添加依赖项:
javax.api
。
尝试添加
<dependencies>
<module name="javax.api"/>
</dependencies>
给你的module.xml
我正在使用 JSPs 和 WildFly 9.0.2.Final,条件如下:
一个JSP文件(test.jsp)正在访问Test.java 文件.
Test.java 文件是 testclient.jar 的一部分,并且已部署为模块.
test.jsp 文件是 Test.ear 的一部分并且已成功部署但是从 test.jsp:
访问 Test.java 文件时出现以下错误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)
这些是 test.jsp 文件的内容 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();
} %>
这些是 Test.java 的内容 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){}
}
}
我认为您需要向模块添加依赖项:
javax.api
。
尝试添加
<dependencies>
<module name="javax.api"/>
</dependencies>
给你的module.xml