使用Jakarta JAXB遭遇ClassNotFoundException的排查与解决
Tomcat 10.1下JAXB XML导入导出的ClassNotFoundException问题解决
项目基础信息
- 开发场景:SQL数据库管理交互Web界面,基于Servlet + Jakarta Servlet JSTL
- 服务器版本:TomCat v10.1
- 目标功能:通过JAXB实现数据的XML格式导入导出
初始报错信息
执行代码JAXBContext context = JAXBContext.newInstance(ExportVeiculo.class);时触发异常:
SEVERE: Servlet.service() for servlet [Servlets.VeiculoServlet] in context with path [/ExamplePath] threw exception [Servlet execution threw an exception] with root cause java.lang.ClassNotFoundException: org.glassfish.jaxb.core.v2.model.annotation.AnnotationReader
已确认问题源于依赖配置,尝试过将相关JAR包放入项目WEB-INF/lib目录及服务器lib目录,均未解决。
依赖补充与错误排查步骤
- 移除
jaxb-impl并添加jaxb-core-3.0.1.jar后,出现新的类缺失错误:
SEVERE: Servlet.service() for servlet [Servlets.VeiculoServlet] in context with path [/ExamplePath] threw exception [Servlet execution threw an exception] with root cause java.lang.ClassNotFoundException: com.sun.istack.Pool
- 补充
istack-commons-runtime-3.0.1.jar后,仍存在类缺失问题:
SEVERE: Servlet.service() for servlet [Servlets.VeiculoServlet] in context with path [/ExamplePath] threw exception [Servlet execution threw an exception] with root cause java.lang.ClassNotFoundException: jakarta.activation.DataSource
最终解决方案
添加Jakarta Activation API 2.0.1依赖后,问题彻底解决。
内容的提问来源于stack exchange,提问作者Letho123
相关产品推荐
相关产品推荐

