【异常】java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher异常解决方法

本文介绍在使用Struts2框架时遇到的JSON导入问题及解决方案,指出除json-lib-2.1-jdk15.jar外还需导入多个依赖包以避免运行时错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    今天在做web项目时用到JSONObject,用的是MyEclipse自动导入的struts2的lib,其中自带了json-lib-2.1-jdk15.jar。

    在struts2的action中已经导入了net.sf.json.JSONObject包。发现用到JSONObject jsonObject = new JSONObject()时,MyEclipse是没有报错的,但是到了JSONObject jsonObject = new JSONObject()时就是执行不下去!

HTTP Status 500 -


type Exception report

message

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.reflect.InvocationTargetException
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	……………………
	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

root cause

java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
	mapsns.action.Login.login(Login.java:34)
	……………………
	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

root cause

java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
	……………………
	org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
	org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.30 logs.


Apache Tomcat/7.0.30



        其中发现java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher,很明显是没有找到相应的class。原来是除了要导入json-lib-2.1-jdk15.jar包外,还要导入其它几个依赖包:commons-beanutils.jar,commons-httpclient.jar,commons-lang.jar,ezmorph.jar,morph-1.0.1.jar

      点击下载依赖jar包

       导入这几个依赖包之后就不再出错了!

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值