1. 程式人生 > >通過Maven新增Oracle驅動依賴的步驟及問題

通過Maven新增Oracle驅動依賴的步驟及問題

一、在maven3的pom.xml中新增依賴

        <!-- Spring Boot JDBC -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        
        <!-- 本地oracle -->
        <dependency>
            <groupId>ojdbc</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4</version>
        </dependency>

二、下載Oracle驅動包

  • 官網下載
  • Maven中央倉庫
  • 本地Oracle資料庫安裝目錄中獲取

       D:\Program Files\PLSQL Developer\instantclient_11_2\ojdbc6.jar(我的路徑)

       注意:不知道本地Oracle的版本,可以通過 SELECT * FROM V$VERSION; 查詢

       

三、將Oracle驅動包載入到Maven的本地倉庫

  • mvn -version檢查Maven環境變數配置
  • cmd 切換到驅動包路徑下
  • mvn -X install:install-file -DgroupId=ojdbc -DartifactId=ojdbc6 -Dversion=11.2.0.4 -Dpackaging=jar -Dfile=ojdbc6.jar

       執行成功的效果:

       

四、相關問題

  • 解決辦法:使用CMD命令列,不能用powershell!
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (D:\Program Files\PLSQL Developer\instantclient_11_2). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException
  • 解決辦法:通過debug模式檢視報錯原因,可能是settings.xml檔案未配置代理導致。
[ERROR] No plugin found for prefix 'install' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (D:\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

擴充套件:通過Eclipse載入Oracle驅動包