gpt4 book ai didi

jdbc - 如何在Gradle项目中使用Oracle JDBC驱动程序

转载 作者:行者123 更新时间:2023-12-02 05:34:11 26 4
gpt4 key购买 nike

我是 Gradle 项目的新手,我有一个问题。我在互联网上搜索过,但找不到我需要的东西,或者也许我不知道如何搜索。首先我要告诉你我的案例。我有一个 Gradle 项目,我想执行几个自动化测试,将来使用 jenkins,但现在我想在 Eclipse 上尝试。我在/lib 目录中有 oracle jdbc 驱动程序,这是我的 build.gradle

    apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
jcenter()
//mavenCentral()
}

// In this section you declare the dependencies for your production and test code
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'org.seleniumhq.selenium:selenium-java:2.+'
compile 'org.testng:testng:6.+'
//compile 'com.oracle:ojdbc14:10.2.0.4.0'
//testCompile 'net.sourceforge.jexcelapi:jxl:2.6.12'
testCompile 'info.cukes:cucumber-core:1.+'
testCompile 'info.cukes:cucumber-java:1.+'
testCompile 'info.cukes:cucumber-junit:1.+'
testCompile 'junit:junit:4.12'
}

repositories {
flatDir(dir: 'libs')//, name: 'Local libs'
}

dependencies {
compile name: 'ojdbc7'
}

我想在一个类中使用这个 jdbc 驱动程序,但我不知道如何使用它。当我尝试使用 Maven 时,我使用了这种方式“import oracle.jdbc.driver.OracleDriver;”但我想这对于 Gradle 项目无效。你能帮我吗?提前致谢

最佳答案

您可以尝试为 Gradle 重用本地 Maven 存储库:

  • 从 Oracle 站点下载 ojdbc7.jar
  • 将 jar 安装到本地 Maven 存储库中:

    mvn install:install-file -Dfile=ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.1 -Dpackaging=jar
  • 检查您是否已将 jar 安装到 ~/.m2/ 本地 Maven 存储库

  • build.gradle 文件中启用本地 Maven 存储库:

    repositories {  
    mavenCentral()
    mavenLocal()
    }

    dependencies {
    compile ("com.oracle:ojdbc7:12.1.0.1")
    }
  • 现在您应该在项目中启用该 jar 进行编译

关于jdbc - 如何在Gradle项目中使用Oracle JDBC驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37458661/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com