如何在Gradle项目中使用Oracle JDBC驱动程序 [英] How to use Oracle JDBC driver in Gradle project
问题描述
我是Gradle项目的新手,我有一个问题。我在互联网上搜索,但我找不到我需要的,或者我不知道如何搜索它。
首先我要告诉你我的情况。我有一个Gradle项目,我想在将来用jenkins执行几个自动化测试,但现在我想尝试Eclipse。
我在/ lib目录中有oracle jdbc驱动程序,这是我的build.gradle
I'm new with Gradle projects and I have one question. I've searched in Internet but I couldn't find what I need or maybe I couldn't know how to search it. First I'm going to tell you my case. I have a Gradle project and I would like to execute several automated tests, in the future with jenkins, but now I want to try on Eclipse. I have the oracle jdbc driver in /lib directory, and this is my 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项目无效。
你能帮助我吗?
在此先感谢
I'd like to use this jdbc driver in one class but I don't know how to use it. When I tried with Maven I used this way "import oracle.jdbc.driver.OracleDriver;" but I guess this is not valid for Gradle project. Can you help me, please? Thanks in advance
推荐答案
您可以简单地将jar添加为依赖项,如下所示:
You can simply add a jar as dependency, like so:
compile files('libs/ojdbc7.jar')
在这种情况下,不需要添加flatDir存储库。请阅读官方用户指南
And there is no need to add a flatDir repository in that case. Read about it in the official user guide
这篇关于如何在Gradle项目中使用Oracle JDBC驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!