通过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驱动包

  • 官网下载

       https://www.oracle.com/technetwork/database/application-development/jdbc/downloads/index.html

  • Maven中央仓库

       http://mvnrepository.com/

  • 本地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驱动包

猜你喜欢

转载自blog.csdn.net/kuibuzhiqianli/article/details/82865675
今日推荐