java - NoClassDefFoundError 仅适用于 EAR 中的特定类

标签 java jakarta-ee

下面是耳朵结构

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。如果在实例化BeanMapperCommonUtil 时发生异常,请仔细检查NoClassDefFoundError 之前的日志。

关于java - NoClassDefFoundError 仅适用于 EAR 中的特定类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10810405/

相关文章:

java - 如何在 Intellij 中查找字符串中以大写字母开头的单词?

java - 使用请求范围时的线程安全代码

java - 使用 Netbeans 部署 GlassFish 生成 java.net.MalformedURLException : Bad URL path

jakarta-ee - 从 IntelliJ 代码格式中排除页面中的部分

java - 使用 JNA 和 Windows sendMessage API 从基于 java 的 Web 应用程序更改 Windows XP 中的焦点窗口

javascript - 用于验证 AS 编号的正则表达式

java - 无法在 Android 上使用 OpenCV 在 for 循环中裁剪图像

java - 从 Java 中的 Locale 获取语言的字母表

jakarta-ee - 正确的 : Java "enterprise" edition = Java "internet" edition?

Java:如何在sql查询中使用多个参数在jdbc中执行preparedStatement?