使用Maven管理Oracle驅動包

來源:互聯網
上載者:User

標籤:

  由於Oracle授權問題,Maven3不提供Oracle JDBC driver,為了在Maven項目中應用Oracle JDBC driver,必須手動添加到本地倉庫。

手動添加到本地倉庫需要本地有oracle驅動包,有兩種方式擷取oracle的驅動包:一種是去oracle官網下載,另一種是如果本地安裝了對應版本的oracle,可以在安裝檔案中找到。

一、下載oracle驅動包

  1.oracle官方網站上下載:

  如果本地沒有安裝Oracle資料庫的話,可以從Oracle官網上邊進行下載:

  :http://www.oracle.com/technetwork/indexes/downloads/index.html

  2.從本地安裝的oracle目錄中擷取

  如果本地安裝著Oracle資料庫的話,可以從安裝路徑:E:\app\product\11.2.0\dbhome_1\jdbc\lib(我的路徑),一般選擇ojdbc6.jar。

  如果不知道本地oracle的版本可以通過:SELECT * FROM v$version;結果如下所示:

  

二、載入到本地maven庫中

  mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.5.0 -Dpackaging=jar -Dfile=本地路徑\ojdbc12.jar

  mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.1.0 -Dpackaging=jar -          Dfile=D:\app\Lenovo\product\11.1.0\db_1\jdbc\lib\ojdbc6.jar 

  特別要注意DartifactId和Dversion與使用的jar版本一致

  將該命令複製到cmd命令提示字元中進行執行:

  

  前提是maven環境變數配置了,如果沒有配置需要首先進入到maven的bin目錄中。

  執行結果:

  

  表示成功。

三、安裝完後,在pom.xml檔案中添加引用

  1.oralce 10g的例子

<dependencies>    <!-- 添加oracle jdbc driver -->      <dependency>            <groupId>com.oracle</groupId>            <artifactId>ojdbc14</artifactId>            <version>10.2.0.4.0</version>    </dependency> </dependencies>

  2.oracle 11g的例子

<dependency>    <groupId>com.oracle</groupId>    <artifactId>ojdbc6</artifactId>    <version>11.2.0.1.0</version></dependency>

  需要注意的是:上述xml檔案中的groupId,artifactId,version必須和使用“mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.1.0 -Dpackaging=jar -          Dfile=D:\app\Lenovo\product\11.1.0\db_1\jdbc\lib\ojdbc6.jar”中的一致。

  

  參考文章:1.http://www.cnblogs.com/leiOOlei/archive/2013/10/21/3380568.html

       2.http://m.blog.csdn.net/blog/jinsique/38312375

       3.http://blog.csdn.net/cnham/article/details/5388016

  

使用Maven管理Oracle驅動包

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.