Maven-Maven中添加Oracle驱动包到本地仓库

举报
小工匠 发表于 2021/09/09 23:18:16 2021/09/09
【摘要】 问题解决办法 1 确认本机安装了Maven2下载对应版本的数据库驱动 官方下载jar通过本地安装目录查找oracle的驱动包说明 3安装驱动到本地仓库pomxml 中使用Oracl...

问题

因Oracle授权问题,Maven3不提供Oracle JDBC 对应的驱动jar包。 因此 ,如果在在Maven项目中使用Oracle JDBC driver,必须手动添加到本地仓库。

解决办法

1、 确认本机安装了Maven

在命令窗口通过mvn -v查看版本

E:\libs\oracle>mvn -v
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T15:39:06-04:00)
Maven home: E:\libs\apache-maven-3.5.0-bin\apache-maven-3.5.0\bin\..
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: E:\Program Files\Java\jdk1.7.0_51\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 8", version: "6.2", arch: "amd64", family: "windows"
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2、下载对应版本的数据库驱动

官方下载jar:

http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html

查看自己的数据库版本,下载对应版本的jar包

这里写图片描述

这里写图片描述

Oracle Database 11g Release 2 (11.2.0.4), (11.2.0.3), (11.2.0.2.0), (11.2.0.1.0) drivers 对应的 jar包为 ojdbc6.jar


通过本地安装目录查找

如果你在本机装了oracle,在 {ORACLE_HOME}\jdbc\lib下查找


oracle的驱动包说明

    classes12.jar - for Java 1.2 and 1.3

    ojdbc14.jar - for Java 1.4 and 1.5

    ojdbc5.jar - for Java 1.5

    ojdbc6.jar - for Java 1.6

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

因此最高的版本 目前是 ojdbc6 .


3、安装驱动到本地仓库

进入到对应的目录,执行 mvn install 命令

Microsoft Windows [版本 10.0.14393]
(c) 2016 Microsoft Corporation。保留所有权利。

C:\Users\Mr.Yang>E:

E:\>cd libs

E:\libs>cd oracle

E:\libs\oracle>mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.4.0 -Dpackaging=jar -Dfile=ojdbc6.jar
[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (3.9 kB at 3.3 kB/s)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom (6.4 kB at 24 kB/s)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom (2.5 kB at 11 kB/s)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom (1.1 kB at 4.3 kB/s)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom (5.0 kB at 14 kB/s)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom (7.2 kB at 17 kB/s)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom (7.3 kB at 24 kB/s)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar (12 kB at 7.9 kB/s)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar (230 kB at 64 kB/s)
[INFO] Installing E:\libs\oracle\ojdbc6.jar to C:\Users\Mr.Yang\.m2\repository\com\oracle\ojdbc6\11.2.0.4.0\ojdbc6-11.2.0.4.0.jar
[INFO] Installing C:\Users\MR15A7~1.YAN\AppData\Local\Temp\mvninstall6899666971437725340.pom to C:\Users\Mr.Yang\.m2\repository\com\oracle\ojdbc6\11.2.0.4.0\ojdbc6-11.2.0.4.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.956 s
[INFO] Finished at: 2017-06-24T17:35:46-04:00
[INFO] Final Memory: 13M/192M
[INFO] ------------------------------------------------------------------------

E:\libs\oracle>
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

[INFO] BUILD SUCCESS 即 OK

这里写图片描述


pom.xml 中使用Oracle驱动包

<!-- 添加oracle jdbc driver -->  
 <dependency>    
     <groupId>com.oracle</groupId>    
     <artifactId>ojdbc6</artifactId>    
     <version>${oracle.version}</version>
 </dependency>
  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

这里写图片描述

接下来,就可以在应用中正常使用Oracle的驱动包了。

文章来源: artisan.blog.csdn.net,作者:小小工匠,版权归原作者所有,如需转载,请联系作者。

原文链接:artisan.blog.csdn.net/article/details/73699100

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。