java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Im building Maven Java Web application and when I do

Class.forName("com.mysql.jdbc.Driver");

I get

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

mysql-connector is added to my pom.xml file like this

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.32</version>
<scope>provided</scope>
</dependency>

But I keep getting this. I even tried downloading mysql-connector and adding it manually to project, but it doesn't change anything.

I also have the same app without Maven, and same code works fine

Answer:

You have set the scope of your dependency as provided. This means that the jar is used when compiling the project (although you shouldn't need it to compile it, since you should only use standard JDBC classes), but that it's not included in the jar or war created by the build, because this dependency is supposed to be "provided" by the application server where you deploy the application.

So, either you actually intend to have this jar provided, and it should be in the application server's classpath, or you want to bundle this jar with the application, and it should have the scope runtime(because you need it to run the app, but not to compile it), instead of provided.

QA-IDEA中用maven配置项目无法加载JDBC的更多相关文章

  1. Maven配置本地库加载ojdbc14-10.2.0.4.0.jar文件

    因为ojdbc14-10.2.0.4.0.jar是要收费的,所以Maven的远程库里没有这个资源,只能通过配置本地库来加载到J2EE工程里,做法如下:   第一步:在网上下载ojdbc14.jar,然 ...

  2. Maven配置项目依赖使用本地仓库的方法汇总

    Maven配置项目使用本地仓库有以下方式实现: 1.类似本地仓库,但是属于本地依赖,比如某个JAR包是引用第三方的,直接放在了项目的lib文件夹,那么此时可以如下配置项目的POM: <depen ...

  3. Springboot项目自动加载设置

    SpringBoot是允许项目自动加载的,但是需要在pom文件映入依赖库 1.导入依赖库 <dependency> <groupId>org.springframework.b ...

  4. Smart3D系列教程7之 《手动配置S3C索引加载全部的瓦片数据》

    一.前言 迄今为止,Wish3D已经出品推出了6篇系列教程,从倾斜摄影的原理方法.采集照片的技巧.Smart3D各模块的功能应用.小物件的照片重建.大区域的地形重建到DSM及正射影像的处理生产,立足于 ...

  5. quartz.net 项目无法加载的问题

    最近尝试试用一下quartz.net 做任务调度用. 下载了源代码后打开解决方案发现项目无法加载.错误如下 未找到导入的项目“C:\Users\****\Desktop\Quartz.NET-2.1. ...

  6. 无法加载ISAPI 筛选器 当前配置只支持加载为 AMD64 处理器体系结构创建的映像

    无法加载ISAPI 筛选器 当前配置只支持加载为 AMD64 处理器体系结构创建的映像 2011-11-9 0:18:49来源:本站原创作者:清晨320我要评论(0) 今天服务器的伪静态死活加载不上去 ...

  7. 007-spring cloud gateway-GatewayAutoConfiguration核心配置-RouteDefinition初始化加载

    一.RouteDefinitionLocator 在Spring-Cloud-Gateway的GatewayAutoConfiguration初始化加载中会加载RouteDefinitionLocat ...

  8. vue-loader 调用了cssLoaders方法配置了css加载器属性。

    module: { loaders: [ // 这里也是相应的配置,test就是匹配文件,loader是加载器, { test: /\.vue$/, loader: 'vue' }, { test: ...

  9. DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描

    DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许进制转载  吐槽之后应该有所改了,该方式可以作为一种过渡方式 ...

随机推荐

  1. less变量插值

    在使用less的过程中,我在background的中引用图片路径,希望先确定一个baseurl,然后再在url中使用拼接字符串的方式拼接,尝试多次,失败. 实际上less的变量插值是有自己的一套规则的 ...

  2. HTML5在线状态检测和DOM Storage

    除了离线资源缓存外,html5离线应用开发还可能用到以下技术 在线状态检测 navigator.onLine navigator.onLine 属性表示当前是否在线.如果为 true, 表示在线:如果 ...

  3. Java动态代理的理解

    代码内容: https://github.com/cjy513203427/Java_Advanced_Knowledge/tree/master/src/com/advance/dynamic_pr ...

  4. iOS 模拟器截屏快捷键

    iOS 模拟器截屏快捷键: cmd+S

  5. DIY了一下自己blog的UI

    当年才学前端时就想改自己blog的UI,然鹅当时没看见那个“申请JS权限”,一直以为blog不能随意DIY样式,只改了少许CSS.现在重新看看设置管理选项,简单修改了一下样式(注意:修改样式之前发邮件 ...

  6. The Internet Communications Engine (Ice) 跨平台异构通讯方案 第二弹-Hello world!

    如果不知道ICE是什么的同学,请看上一篇的ICE简介:http://www.cnblogs.com/winds/p/3864677.html 好了,HelloWorld,从中间语言讲起. 首先,我们新 ...

  7. php strpos返回字符串首次出现的位置

    (PHP 4, PHP 5, PHP 7) strpos — 查找字符串首次出现的位置 说明 mixed strpos ( string $haystack , mixed $needle [, in ...

  8. Jvm运行时内存解析

    一.jvm的概念 在了解jvm的概念之前,我们先来了解java平台的逻辑结构,图片来自<深入java虚拟机> 从图中我们可以看到jdk包含了jre,java语言和java开发工具和Api, ...

  9. maven(5)--依赖特性

    依赖的子标签中有scope,常用值有compile.provide.test.runtime compile:编译范围有效,即编译和打包时都会将这个依赖存储 provide:编译测试有效,但是打包是将 ...

  10. thinkphp更新数据库的时候where('')为字符串

    if($user->where('phone='.$phone)->save($dataList)){} if($user->where(array('phone' =>$ph ...