oracle 如何通过 Gradle 将 ojdbc7 添加到 Java Web 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37783669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add ojdbc7 to Java web app by Gradle?
提问by Do Nhu Vy
My context:
我的背景:
- I build a Java web application what based on Spring Boot 1.3.5.RELEASE .
- I try to add
ojdcb
to dependencies list but not success. - I know that Oracle has own Maven repository at
http://maven.oracle.com
- 我构建了一个基于 Spring Boot 1.3.5.RELEASE 的 Java Web 应用程序。
- 我尝试添加
ojdcb
到依赖项列表但没有成功。 - 我知道 Oracle 有自己的 Maven 存储库,位于
http://maven.oracle.com
This is my build.gradle
file, Let focus at line 4, 5, 6, 36:
这是我的build.gradle
文件,让我们关注第 4、5、6、36 行:
buildscript {
repositories {
mavenCentral()
maven {
url ("https://maven.oracle.com")
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE")
}
}
apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'erp'
version = '1.0.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
//compile("org.springframework.boot:spring-boot-starter-security")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.hibernate:hibernate-core")
compile("com.oracle.jdbc:ojdbc7:12.1.0.2")
testCompile("junit:junit")
}
IntelliJ IDEA 2016 notice error:
IntelliJ IDEA 2016 提示错误:
Warning:root project 'erp': Web Facets/Artifacts will not be configured properlyDetails: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':runtime'. Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find com.oracle.jdbc:ojdbc7:12.1.0.2. Required by: :erp:unspecified
警告:根项目“erp”:Web Facets/Artifacts 将无法正确配置详细信息:org.gradle.api.artifacts.ResolveException:无法解析配置“:runtime”的所有依赖项。引起:org.gradle.internal.resolve.ModuleVersionNotFoundException: 找不到 com.oracle.jdbc:ojdbc7:12.1.0.2。需要: :erp:unspecified
(Related links: http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9015https://blogs.oracle.com/dev2dev/entry/how_to_get_oracle_jdbchttps://blogs.oracle.com/dev2dev/entry/oracle_maven_repository_instructions_for)
(相关链接:http: //docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9015 https://blogs.oracle.com/dev2dev/entry/how_to_get_oracle_jdbc https://blogs.oracle。 com/dev2dev/entry/oracle_maven_repository_instructions_for)
Help me add ojdbc
to dependencies list by Gradle, thank you!
帮助我ojdbc
通过 Gradle添加到依赖项列表,谢谢!
采纳答案by Do Nhu Vy
For Oracle database 12c
对于 Oracle 数据库 12c
(1)Download ojdbc7.jar
at Oracle homepage.
(1)ojdbc7.jar
在 Oracle 主页下载。
(2)Run command
(2)运行命令
mvn install:install-file -Dfile=ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.1 -Dpackaging=jar
(3)Add to build.gradle
(3)添加到build.gradle
compile('com.oracle:ojdbc7:12.1.0.1')
回答by Robin A. Meade
Gradle currently can't handle the redirects needed by the realm-based SSO mechanism used by Oracle's maven repo.
Gradle 当前无法处理 Oracle 的 maven 存储库使用的基于领域的 SSO 机制所需的重定向。
A workaroundis to use this URL instead
一个解决办法是使用这个网址,而不是
url "https://www.oracle.com/content/secure/maven/content"
In addition, you need to supply credentials for authentication.
此外,您需要提供用于身份验证的凭据。
Here's a minimal example:
这是一个最小的例子:
plugins {
id 'java'
}
repositories {
jcenter()
maven {
url "https://www.oracle.com/content/secure/maven/content"
credentials {
username = '<Oracle Account email address>'
password = '<Oracle Account password>'
}
}
}
dependencies {
compile 'com.oracle.jdbc:ojdbc7:12.1.0.2'
}
I have a github repo with full example including a way of encrypting the password using maven's settings.xml
and settings-security.xml
: example-gradle-oracle
我有一个包含完整示例的 github 存储库,其中包括一种使用 mavensettings.xml
和settings-security.xml
: example-gradle-oracle加密密码的方法
I am adding = after username and password as mentioned in Gradle AuthenticationSupported.java file
我在 Gradle AuthenticationSupported.java 文件中提到的用户名和密码之后添加 =
回答by Jupeter
Your build.gradle will work if you replace:
如果您替换,您的 build.gradle 将起作用:
maven {
url ("https://maven.oracle.com")
}
to:
到:
maven {
url "https://www.oracle.com/content/secure/maven/content"
name "maven.oracle.com"
credentials {
username '[email protected]'
password 'your password'
}
}
Credetials from Oracle Registration page: https://profile.oracle.com/myprofile/account/create-account.jspx.
来自 Oracle 注册页面的凭据:https://profile.oracle.com/myprofile/account/create-account.jspx 。
Additionally:
此外:
To place authentication data outside of project home, you can edit configuration file ~/.gradle/gradle.properties
:
要将身份验证数据放置在项目主页之外,您可以编辑配置文件~/.gradle/gradle.properties
:
[email protected]
mavenOraclePassword=your password
and use it in configuration like:
并在如下配置中使用它:
credentials {
username mavenOracleUsername
password mavenOraclePassword
}
回答by Gustavo Rozolin
I've added the http://nexus.saas.hand-china.com/content/repositories/rdc/repo and work
我添加了http://nexus.saas.hand-china.com/content/repositories/rdc/repo 并工作
repositories {
mavenCentral()
//Add this repo
maven {
url "http://nexus.saas.hand-china.com/content/repositories/rdc/"
}
}
...
dependencies {
....
compile group: 'com.oracle', name: 'ojdbc7', version: '12.1.0.2'
}