由于Oracle授权问题,Maven3不提供Oracle JDBC driver,为了在Maven项目中应用Oracle JDBC driver,必须手动添加到本地仓库。
此文档用的是Oracle 11g.
一.首先要得到Oracle JDBC Driver
1.通过Oracle官方网站下载相应版本:http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
2.通过Oracle的安装目录获得,位置在“{ORACLE_HOME}\jdbc\lib\ojdbc6.jar”
补充:
oracle安装目录的db_1/jdbc/lib目录下有
ojdbc5.jar ojdbc5_g.jar ojdbc5dms.jar
ojdbc5dms_g.jar ojdbc6.jar ojdbc6_g.jar
ojdbc6dms.jar ojdbc6dms_g.jar
这几个jar包,那么该用哪个驱动 版本是11G
这个要取决于你的jdk,如果你的jdk是1.5用ojdbc5.jar,如果jdk是1.6用ojdbc6.jar 。
ojdbc5_g.jar、ojdbc6dms_g.jar 只是用javac -g编译,生成所有调试信息
因为写者装的是1.7的jdk 故在此使用的是ojdbc6.jar
二.手动安装
命令如下:
mvn install:install-file -Dfile=D:\app\nyp\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
D:\app\nyp\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar:此为笔者的ojdbc6.jar绝对路径
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
|
D:\IdeaProjects\springdemo>mvn install:install-file -Dfile=D:\app\nyp\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar -DgroupId=com.oracle -DartifactId=oj
dbc6 -Dversion=11.2.0 -Dpackaging=jar
[INFO] Scanning for projects...
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.4.3/maven-surefire-plugin-2.4.3.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.4.3/maven-surefire-plugin-2.4.3.pom (7 KB at 1.3 KB/s
ec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire/2.4.3/surefire-2.4.3.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire/2.4.3/surefire-2.4.3.pom (8 KB at 4.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/7/maven-parent-7.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/7/maven-parent-7.pom (21 KB at 6.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.4.3/maven-surefire-plugin-2.4.3.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.4.3/maven-surefire-plugin-2.4.3.jar (23 KB at 13.2 KB
/sec)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building springdemo Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ springdemo ---
[INFO] Installing D:\app\nyp\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar to C:\Users\nyp\.m2\repository\com\oracle\ojdbc6\11.2.0\ojdbc6-11.2.0.jar
[INFO] Installing C:\Users\nyp\AppData\Local\Temp\mvninstall6636656554080089052.pom to C:\Users\nyp\.m2\repository\com\oracle\ojdbc6\11.2.0\ojdbc6-11.
2.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 22.976s
[INFO] Finished at: Sat Feb 14 14:35:10 CST 2015
[INFO] Final Memory: 6M/59M
[INFO] ------------------------------------------------------------------------
D:\IdeaProjects\springdemo>
|
to C:\Users\nyp\.m2\多注意,如果是build后的路径不是亲的本地仓库,那么就要麻烦你手动复制过去了
三.安装完后,在pom.xml文件中添加引用
1
2
3
4
5
6
7
8
|
<
dependencies
>
<!-- 添加oracle jdbc driver -->
<
dependency
>
<
groupId
>com.oracle</
groupId
>
<
artifactId
>ojdbc6</
artifactId
>
<
version
>11.2.0</
version
>
</
dependency
>
</
dependencies
>
|
好了,现在可以正常引用了。个人经验,希望对大家有所帮助。