普通java Project 引入jar包:

1,copy jar to lib folder.

2, imported with Build path -> Add external jars, and it worked perfectly.

Java Web Project 引入jar包:

1,copy jar to WebContent/WEB-INF/lib/

2,right click jar Package Build path -> Add external jars。

说明:

http://stackoverflow.com/questions/30384473/how-to-import-jdbc-driver-into-dynamic-web-project

There are two ways to use and reference a jar file in an eclipse project.

  • One is at compile time and for compilation purposes. To make your project compile, you need to add your required libraries in the classpath. In eclipse, right click to your project, hover on 'Build Path', then select 'Configure Build Path'. In the dialog go to 'Libraries' tab and there you can see which jars/libraries you have. If you need to add more, you can use the buttons at the right side of the dialog. There you should select 'Add external jars' and select the MySql JDBC Driver from your file system.

  • The other one is at run time. This is when you deploy your web application to an application server. Now everytime your application needs to load a class from an external jar, it will look for the jar in the application server's class loader. The classloader conatins the paths to the available jar files in your application server, in configured resources and in your deployed application in the WEB-INF/lib/ folder. You can configure which place the classloader will check first.

In your very specific case, you need to add the MySQL JDBC Driver in any of classloader paths (since I asume your project compiles already) so you can either add the jar to Tomcat's /lib directory or to your application's /WEB-INF/lib/ directory. After that just redeploy or restart tomcat and you should be able to use MySQL JDBC connections.

UPDATE:

Also, when using a DriverManager interface to create a JDBC Connection, remember to always create an instance of your JDBC driver first in order to load it into your Classloader. You can see this in the MySQL JDBC Driver documentation. Ej:

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

Call this line before using DriverManager.getConnection(...) and you should now be able to create and use your JDBC Connections.

Java项目引入第三方Jar包的更多相关文章

  1. eclipse 项目引入第三方jar包 3种方法

    我们在用Eclipse开发程序的时候,经常要用到第三方jar包.引入jar包不是一个小问题,由于jar包位置不清楚,而浪费时间.下面配图说明3种Eclipse引入jar包的方式. 1.最常用的普通操作 ...

  2. Mavn 项目 引入第三方jar包 导致ClassNotFoundException

    案例 我有一个Maven构建的项目,项目模块之间有依赖关系,我需要用到一个本地的jar包,而该jar包不能通过配置pom.xml文件从远程仓库自动下载,于是我直接导入该jar包到其中一个项目,不通过p ...

  3. [Java][RCP] 引入第三方jar包时出错: XXXcannot be found XXX

    为什么会这样? 下面的博客有介绍,不在累赘 http://dengmin.iteye.com/blog/260585 这些博客貌似忘掉了一点,或者是我本地的Eclipse新建的项目Version不够高 ...

  4. 【转】Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法)

    原文网址:http://www.blogjava.net/anchor110/articles/355699.html 1.在工程下新建lib文件夹,将需要的第三方包拷贝进来.2.将引用的第三方包,添 ...

  5. Java项目导出为jar包+导出第三方jar包+使用命令行调用+传参

    Java项目导出为jar包+导出第三方jar包+使用命令行调用+传参 一.打包 情况1:不需要向程序传参数,并且程序没有使用第三方jar包 Eclipse上导出jar: 然后选择一个java文件作为入 ...

  6. SpringBoot快速引入第三方jar包

    工作中,我们常会用到第三方jar包,而这些jar包往往在maven仓库是搜不到的,下面推荐一种简单.快速的引入第三方依赖的方法: 比如第三方jar包在lib文件夹下,对pom.xml的配置如下: &l ...

  7. springboot打成jar包和war包的两种方式,并引入第三方jar包!

    springboot打成jar包和war包的两种方式,并引入第三方jar包! 首先把需要引入的第三方jar包引入到本地项目中,在引用的模块下加一个lib文件夹 一.打成jar包 1.修改pom文件里的 ...

  8. java——引入第三方jar包

    第一步:项目->New->Folder:创建一个文件夹: 第二步:把要引入的jar包粘贴到新建的文件夹中: 第三步:选中引入的jar包->Build Path->Add to ...

  9. myeclipse8.5打包jar并引入第三方jar包

    用myeclipse自带的export工具,无法引入被引用的第三方的jar包,有两种方式: (1)直接export出jar包,解压jar包(第三方的jar包太多,太麻烦) 在创建好的JAR文件里找到M ...

  10. 【JMeter】Jmeter引入第三方jar包

    Jmeter做remoteService,里面用到一个实体:clickEntity,是在一个第三方jar包定义的:com.bj58.opt.ad_logparser-0.0.18-SNAPSHOT.j ...

随机推荐

  1. FTCL:Fine-grained Temporal Contrastive Learning for Weakly-supervised Temporal Action Localization概述

    1.针对的问题 现有的方法主要遵循于通过优化视频级分类目标来实现定位的方式,这些方法大多忽略了视频之间丰富的时序对比关系,因此在分类学习和分类-定位自适应的过程中面临着极大的模糊性.(1)在弱监督设置 ...

  2. k8s网路策略

    Network Policy(网络策略) 默认情况下,k8s集群网络是没有任何限制的,Pod可以和任何其他Pod通信,在某些场景下需要做网络控制,减少网络面的攻击,提高安全性,就会用到网络策略(Net ...

  3. 关于使用C++调用WCF的方法

    因为近期要对接别人的接口,使用的是wcf,因为之前没有使用过wcf,更不了解它,于是在使用的时候出现了很多问题. 下面就记录一下下 在调用方法之前,我们一般都会拿到一个地址,http://xxxxxx ...

  4. elementUi-2.13.2版本添加暂无数据

    1.实现效果如下: 2. 代码实现 <el-table empty-taxt="暂无数据"></el-table> css样式设置: .el-table__ ...

  5. python实现两张图片拼接

    纵向拼接 from PIL import Image def image_splicing(pic01, pic02): """ 图片拼接 :param pic01: 图 ...

  6. phpstudy 配置域名解决index.php 过多重定向

    server { listen 80; server_name www.cqtldd.com cqtldd.com; root "D:/phpstudy_pro/WWW/tongliangd ...

  7. Spring全家桶(一)之Spring总结

    0. Spring常用注解汇总 Spring常用注解汇总 使用注解之前要开启自动扫描功能,其中base-package为需要扫描的包(含子包). <context:component-scan ...

  8. Jmeter使用文档(循环怎么用)

    Jmeter使用文档(循环怎么用) 基础用法 修改语言 Jmeter之界面语言设置 下面使用简体中文的命名进行说明 打开日志 启动后,右上角有个黄色的感叹号图标,点击即可打开即时日志 如果没有看到重启 ...

  9. C# 变量和表达式

    变量的命名: 第一个字符必须是字母.下划线或@: 其后的字符可以是字母.下划线或数字. 注意:区分大小写. 变量的类型: 数值类型 1.整数类型 byte.short.int.long sbyte.u ...

  10. 【azw3】麻省理工深度思考法:从模型及动力机制来思考现象

    书本详情 标题:麻省理工深度思考法:从模型及动力机制来思考现象作者:[日]平井孝志 著:张玉虹 译年份:2018出版社:北京:中国华侨出版社ISBN:9787511373441,7511373445格 ...