Error:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader.findClass

本文介绍了一种常见的Eclipse开发环境中,连接数据库时出现的错误及其解决方案。通过配置项目构建路径并添加mysql-connector-java.jar,可以有效解决此问题。

每次在Eclipse上运行需要连接数据库的项目都会报这个错

 

久病成医,自己得把解决方法记录下来才行。免得每次都需要去百度。

解决方法:

右键项目名--->Build Path—>Configure Build Path,

选择 Add External Jars

然后选择mysql-connector-java.jar包

(这个jar包的下载地址:https://mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.11

最后点击Apply

 

[2025-08-26 18:28:58] [SEVERE] [ejb-container] [FATAL ERROR: Unknown error in Assembler. com.tongweb.xbean.propertyeditor.PropertyEditorException: Unable to resolve class com.mysql.cj.jdbc.Driver at com.tongweb.xbean.propertyeditor.ClassEditor.toObjectImpl(ClassEditor.java:43) at com.tongweb.xbean.propertyeditor.AbstractConverter.toObject(AbstractConverter.java:86) at com.tongweb.xbean.propertyeditor.PropertyEditors.getValue(PropertyEditors.java:284) at com.tongweb.xbean.recipe.RecipeHelper.convert(RecipeHelper.java:172) at com.tongweb.xbean.recipe.ObjectRecipe.extractConstructorArgs(ObjectRecipe.java:596) at com.tongweb.xbean.recipe.ObjectRecipe.internalCreate(ObjectRecipe.java:276) at com.tongweb.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:96) at com.tongweb.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:61) at com.tongweb.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:49) at com.tongweb.tongejb.assembler.classic.ThorAssembler.createResource(ThorAssembler.java:997) at com.tongweb.tongejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:430) at com.tongweb.tongejb.assembler.classic.Assembler.build(Assembler.java:345) at com.tongweb.tongejb.OpenEJB$Instance.<init>(OpenEJB.java:144) at com.tongweb.tongejb.OpenEJB.init(OpenEJB.java:290) at com.tongweb.twnt.thor.ThorTomcatLoader.initializeModified(ThorTomcatLoader.java:182) at com.tongweb.twnt.thor.ThorTomcatLoader.initialize(ThorTomcatLoader.java:71) at com.tongweb.twnt.thor.TomcatLoader.init(TomcatLoader.java:131) at com.tongweb.twnt.thor.ThorServerListener.lifecycleEvent(ThorServerListener.java:99) at com.tongweb.web.thor.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at com.tongweb.web.thor.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at com.tongweb.web.thor.util.LifecycleBase.setStateInternal(LifecycleBase.java:401) at com.tongweb.web.thor.util.LifecycleBase.init(LifecycleBase.java:110) at com.tongweb.web.thor.util.LifecycleBase.start(LifecycleBase.java:139) at com.tongweb.web.thor.startup.Tomee.start(Tomee.java:681) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.tongweb.web.thor.startup.ThorBootstrap.start(ThorBootstrap.java:412) at com.tongweb.web.thor.startup.ThorBootstrap.main(ThorBootstrap.java:558) Caused by: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:278) at com.tongweb.xbean.propertyeditor.ClassEditor.toObjectImpl(ClassEditor.java:40) ... 29 more ] [2025-08-26 18:28:58] [SEVERE] [ejb-container] [EJB container has encountered a fatal error and cannot be started: Assembler failed to build the container system.] com.tongweb.tongejb.OpenEJBException: com.tongweb.xbean.propertyeditor.PropertyEditorException: Unable to resolve class com.mysql.cj.jdbc.Driver: Unable to resolve class com.mysql.cj.jdbc.Driver at com.tongweb.tongejb.assembler.classic.Assembler.build(Assembler.java:358) at com.tongweb.tongejb.OpenEJB$Instance.<init>(OpenEJB.java:144) at com.tongweb.tongejb.OpenEJB.init(OpenEJB.java:290) at com.tongweb.twnt.thor.ThorTomcatLoader.initializeModified(ThorTomcatLoader.java:182) at com.tongweb.twnt.thor.ThorTomcatLoader.initialize(ThorTomcatLoader.java:71) at com.tongweb.twnt.thor.TomcatLoader.init(TomcatLoader.java:131) at com.tongweb.twnt.thor.ThorServerListener.lifecycleEvent(ThorServerListener.java:99) at com.tongweb.web.thor.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at com.tongweb.web.thor.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at com.tongweb.web.thor.util.LifecycleBase.setStateInternal(LifecycleBase.java:401) at com.tongweb.web.thor.util.LifecycleBase.init(LifecycleBase.java:110) at com.tongweb.web.thor.util.LifecycleBase.start(LifecycleBase.java:139) at com.tongweb.web.thor.startup.Tomee.start(Tomee.java:681) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.tongweb.web.thor.startup.ThorBootstrap.start(ThorBootstrap.java:412) at com.tongweb.web.thor.startup.ThorBootstrap.main(ThorBootstrap.java:558) Caused by: com.tongweb.xbean.propertyeditor.PropertyEditorException: Unable to resolve class com.mysql.cj.jdbc.Driver at com.tongweb.xbean.propertyeditor.ClassEditor.toObjectImpl(ClassEditor.java:43) at com.tongweb.xbean.propertyeditor.AbstractConverter.toObject(AbstractConverter.java:86) at com.tongweb.xbean.propertyeditor.PropertyEditors.getValue(PropertyEditors.java:284) at com.tongweb.xbean.recipe.RecipeHelper.convert(RecipeHelper.java:172) at com.tongweb.xbean.recipe.ObjectRecipe.extractConstructorArgs(ObjectRecipe.java:596) at com.tongweb.xbean.recipe.ObjectRecipe.internalCreate(ObjectRecipe.java:276) at com.tongweb.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:96) at com.tongweb.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:61) at com.tongweb.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:49) at com.tongweb.tongejb.assembler.classic.ThorAssembler.createResource(ThorAssembler.java:997) at com.tongweb.tongejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:430) at com.tongweb.tongejb.assembler.classic.Assembler.build(Assembler.java:345) ... 18 more Caused by: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:278) at com.tongweb.xbean.propertyeditor.ClassEditor.toObjectImpl(ClassEditor.java:40) ... 29 more [2025-08-26 18:28:58] [SEVERE] [other] [TongWeb Listener can't start EJB container] com.tongweb.tongejb.OpenEJBException: com.tongweb.xbean.propertyeditor.PropertyEditorException: Unable to resolve class com.mysql.cj.jdbc.Driver: Unable to resolve class com.mysql.cj.jdbc.Driver at com.tongweb.tongejb.assembler.classic.Assembler.build(Assembler.java:358) at com.tongweb.tongejb.OpenEJB$Instance.<init>(OpenEJB.java:144) at com.tongweb.tongejb.OpenEJB.init(OpenEJB.java:290) at com.tongweb.twnt.thor.ThorTomcatLoader.initializeModified(ThorTomcatLoader.java:182) at com.tongweb.twnt.thor.ThorTomcatLoader.initialize(ThorTomcatLoader.java:71) at com.tongweb.twnt.thor.TomcatLoader.init(TomcatLoader.java:131) at com.tongweb.twnt.thor.ThorServerListener.lifecycleEvent(ThorServerListener.java:99) at com.tongweb.web.thor.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at com.tongweb.web.thor.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90) at com.tongweb.web.thor.util.LifecycleBase.setStateInternal(LifecycleBase.java:401) at com.tongweb.web.thor.util.LifecycleBase.init(LifecycleBase.java:110) at com.tongweb.web.thor.util.LifecycleBase.start(LifecycleBase.java:139) at com.tongweb.web.thor.startup.Tomee.start(Tomee.java:681) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.tongweb.web.thor.startup.ThorBootstrap.start(ThorBootstrap.java:412) at com.tongweb.web.thor.startup.ThorBootstrap.main(ThorBootstrap.java:558) Caused by: com.tongweb.xbean.propertyeditor.PropertyEditorException: Unable to resolve class com.mysql.cj.jdbc.Driver at com.tongweb.xbean.propertyeditor.ClassEditor.toObjectImpl(ClassEditor.java:43) at com.tongweb.xbean.propertyeditor.AbstractConverter.toObject(AbstractConverter.java:86) at com.tongweb.xbean.propertyeditor.PropertyEditors.getValue(PropertyEditors.java:284) at com.tongweb.xbean.recipe.RecipeHelper.convert(RecipeHelper.java:172) at com.tongweb.xbean.recipe.ObjectRecipe.extractConstructorArgs(ObjectRecipe.java:596) at com.tongweb.xbean.recipe.ObjectRecipe.internalCreate(ObjectRecipe.java:276) at com.tongweb.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:96) at com.tongweb.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:61) at com.tongweb.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:49) at com.tongweb.tongejb.assembler.classic.ThorAssembler.createResource(ThorAssembler.java:997) at com.tongweb.tongejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:430) at com.tongweb.tongejb.assembler.classic.Assembler.build(Assembler.java:345) ... 18 more Caused by: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:278) at com.tongweb.xbean.propertyeditor.ClassEditor.toObjectImpl(ClassEditor.java:40) ... 29 more
最新发布
08-27
方案一:将驱动放入 Spark 全局 JAR 目录(推荐) 在所有节点部署 MySQL 驱动,已经部署 25/08/07 11:33:42 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable ❌ 驱动加载失败: An error occurred while calling z:java.lang.Class.forName. : java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:467) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244) at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:374) at py4j.Gateway.invoke(Gateway.java:282) at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132) at py4j.commands.CallCommand.execute(CallCommand.java:79) at py4j.ClientServerConnection.waitForCommands(ClientServerConnection.java:184) at py4j.ClientServerConnection.run(ClientServerConnection.java:108) at java.base/java.lang.Thread.run(Thread.java:842) ⚠️ 请检查: 1. jar包位置 2. spark-defaults.conf配置 3. 文件权限 进程已结束,退出代码为 0 使用的是anaconda的虚拟环境 不使用hdfs mysql8.0,类名正确
08-08
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值