类找不到异常 Caused by: java.lang.NoClassDefFoundError

时间:2023-03-08 19:16:24

  错误原因:在部署应用的时候,服务器报错,Caused by: java.lang.ClassNotFoundException: org.quartz.impl.JobDetailImpl,某个类找不到,找到对应的包发现明明某个jar已经引进去了,在仔细一看发现有三个类似的jar, com.alibaba.external:opensymphony.quartz,opensymphony:quartz,org.quartz-scheduler:quartz。实际上我希望的包,是org.quartz-scheduler:quartz,里面有我希望的org.quartz.impl.JobDetailImpl类,但是发现一个问题opensymphony.quartz,opensymphony:quartz里面也有org.quartz.impl包但是没有JobDetailImpl类,但是JVM在加载类的时候并没有指定用哪个jar,比如加载到opensymphony:quartz的org.quartz.impl包,但是没有发现JobDetailImpl,然后就报错了。

  解决方法:用mvn dependency:tree  获取依赖树,找到哪些包间接引用了,com.alibaba.external:opensymphony.quartz,opensymphony:quartz排除

            <exclusions>
<exclusion>
<groupId>com.alibaba.external</groupId>
<artifactId>opensymphony.quartz</artifactId>
</exclusion>
<exclusion>
<groupId>opensymphony</groupId>
<artifactId>quartz</artifactId>
</exclusion>
</exclusions>

  然后引入org.quartz-scheduler:quartz即可。