下面是耳朵结构
ex.ear | |_lib-util.jar--CommonUtil.class,CommonException.class etc. | | | ejb.jar web.war
When I call this specific class like this (CommonUtil.map(empDto)
) in WEB and EJB layer classes then we are getting a NoClassDefFoundError
. Remaining all classes which are in Util.jar are all getting called normally. Why are we getting this error only for this class?
EmployeeDTO empDto = new EmployeeDTO();
empDto.setId(1);
empDto.setName("john");
CommonUtil.map(empDto);
public class CommonUtil {
private static Mapper mapper = new BeanMapper();
private static CommonUtil instance = new CommonUtil();
private CommonUtil() {
super();
}
public static <T> T map(Object source) {
T target = mapper.map(source);
return target;
}
public static <T> T map(Object source) {
mapper.map(source);
return target;
}
}
最佳答案
一般来说,如果在静态初始化期间发生异常,就会发生 NoClassDefFoundError
。如果在实例化BeanMapper
或CommonUtil
时发生异常,请仔细检查NoClassDefFoundError
之前的日志。
关于java - NoClassDefFoundError 仅适用于 EAR 中的特定类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10810405/