Oracle JDBC ojdbc6 Jar 作为 Maven 依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9898499/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 04:05:23  来源:igfitidea点击:

Oracle JDBC ojdbc6 Jar as a Maven Dependency

oraclemavenjdbcwar

提问by Marvo

I cannot seem to get Maven to bundle the ojdbc6.jar file into my project's war file. I have it working within the POM file when specifying a dependency directly for Hibernate tools. But it won't get bundled with the project's war file, and therefore my project won't run on Tomcat.

我似乎无法让 Maven 将 ojdbc6.jar 文件捆绑到我的项目的 war 文件中。当直接为 Hibernate 工具指定依赖项时,我让它在 POM 文件中工作。但它不会与项目的 war 文件捆绑在一起,因此我的项目不会在 Tomcat 上运行。

I have tried every solution I can find out there on the net, including those specified for this question here:

我已经尝试了我可以在网上找到的所有解决方案,包括针对此问题指定的解决方案:

Find Oracle JDBC driver in Maven repository

在 Maven 存储库中查找 Oracle JDBC 驱动程序

Most recently, I did the following:

最近,我做了以下事情:

  1. Download the jar file to my machine

  2. Run the following command to install the jar into my local repository:

    mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true
    

    (I've tried all kinds of variants of that command, too.)

  3. Finally, I put the dependency into my pom file:

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3</version>
    </dependency>
    
  4. I run a clean build, but it fails:

    mvn -U clean package
    
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building jazztwo 0.0.1
    [INFO] ------------------------------------------------------------------------
    Downloading: http://repo1.maven.org/maven2/com/oracle/ojdbc6/11.2.0.3/ojdbc6-11.2.0.3.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.700s
    [INFO] Finished at: Tue Mar 27 15:06:14 PDT 2012
    [INFO] Final Memory: 3M/81M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project jazztwo: Could not resolve dependencies for project edu.berkeley:jazztwo:war:0.0.1: Could not find artifact com.oracle:ojdbc6:jar:11.2.0.3 in central (http://repo1.maven.org/maven2) -> [Help 1]
    
  1. 将jar文件下载到我的机器上

  2. 运行以下命令将 jar 安装到我的本地存储库中:

    mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true
    

    (我也尝试过该命令的各种变体。)

  3. 最后,我将依赖项放入我的 pom 文件中:

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3</version>
    </dependency>
    
  4. 我运行了一个干净的构建,但它失败了:

    mvn -U clean package
    
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building jazztwo 0.0.1
    [INFO] ------------------------------------------------------------------------
    Downloading: http://repo1.maven.org/maven2/com/oracle/ojdbc6/11.2.0.3/ojdbc6-11.2.0.3.jar
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.700s
    [INFO] Finished at: Tue Mar 27 15:06:14 PDT 2012
    [INFO] Final Memory: 3M/81M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project jazztwo: Could not resolve dependencies for project edu.berkeley:jazztwo:war:0.0.1: Could not find artifact com.oracle:ojdbc6:jar:11.2.0.3 in central (http://repo1.maven.org/maven2) -> [Help 1]
    

Why doesn't this work? I'm ready to throw expensive computer parts across the room. This has wasted so much time. (Thank you, Oracle. How much did we pay you again?)

为什么这不起作用?我准备把昂贵的电脑零件扔到房间里。这浪费了太多时间。(谢谢你,甲骨文。我们又付给你多少钱?)

Is it because I'm on a Mac, perhaps?

也许是因为我在使用 Mac?

采纳答案by Marvo

The correct answer was supplied by Raghuram in the comments section to my original question.

正确答案由 Raghuram 在我的原始问题的评论部分提供。

For whatever reason, pointing "mvn install" to a full path of the physical ojdbc6.jar file didn't work for me. (Or I consistently repeatedly flubbed it up when running the command, but no errors were issued.)

无论出于何种原因,将“mvn install”指向物理 ojdbc6.jar 文件的完整路径对我来说都不起作用。(或者我在运行命令时一直反复把它搞砸,但没有发出错误。)

cd-ing into the directory where I keep ojdb6.jar and running the command from there worked the first time.

cd-ing 进入我保存 ojdb6.jar 的目录并从那里运行命令第一次工作。

If Raghuram would like to answer this question, I'll accept his answer instead. Thanks everyone!

如果拉古拉姆想回答这个问题,我会接受他的回答。谢谢大家!

回答by Ondrej Kvasnovsky

It is better to add new Maven repository (preferably using your own artifactory) to your project instead of installing it to your local repository.

最好将新的 Maven 存储库(最好使用您自己的工件)添加到您的项目中,而不是将其安装到您的本地存储库中。

Maven syntax:

Maven 语法:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.3</version>
</dependency>
... 
<repositories>
    <repository>
      <id>codelds</id>
      <url>https://code.lds.org/nexus/content/groups/main-repo</url>
    </repository>
  </repositories>

Grails example:

Grails 示例:

mavenRepo "https://code.lds.org/nexus/content/groups/main-repo"
build 'com.oracle:ojdbc6:11.2.0.3'

回答by rickygrimes

For anyone reading this post in the future, you don't need to cd to the directory where the jar is present. Here is what you need to do -

对于将来阅读这篇文章的任何人,您都不需要 cd 到 jar 所在的目录。这是你需要做的 -

Go to your project folder from where you can run maven commands (When you do an ls -ltr in this folder, you should see pom.xml)

转到您可以运行 maven 命令的项目文件夹(当您在此文件夹中执行 ls -ltr 时,您应该看到 pom.xml)

Do this -

做这个 -

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=<Path where the jar is, example downloads>/ojdbc6.jar -DgeneratePom=true

Once this is done, you can add the dependency in your pom.xml, something like this -

完成后,您可以在 pom.xml 中添加依赖项,如下所示 -

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3</version>
    </dependency>

回答by Sushil Gulhane

mvn install:install-file 
-Dfile=C:\Users\xxxx\Downloads\lib\ojdbc6.jar 
-DgroupId=com.oracle
-DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

to resolve the ORACLE JAR issue with the Spring Application,

用 Spring 应用程序解决 ORACLE JAR 问题,

Oracle JDBC ojdbc6 Jar as a Maven Dependency

Oracle JDBC ojdbc6 Jar 作为 Maven 依赖项

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0</version>
    </dependency>`

回答by shermi

First you need to download the particular jar from Oracle site (ojdbc.jar version 11.2.0.3)

首先,您需要从 Oracle 站点下载特定的 jar(ojdbc.jar 版本 11.2.0.3)

if you download it to C:\filefolder

如果你把它下载到 C:\filefolder

go to that directory in cmd prompt and provide the below command.It will install the dependency.Then you can build your project.

在 cmd 提示符下转到该目录并提供以下命令。它将安装依赖项。然后您可以构建您的项目。

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dpackaging=jar -Dversion=11.2.0.4.0 -Dfile=ojdbc6.jar -DgeneratePom=true

回答by Barani r

Below config worked for me. Refer this linkfor more details.

下面的配置对我有用。有关更多详细信息,请参阅此链接

<dependency>
 <groupId>com.oracle.jdbc</groupId>
 <artifactId>ojdbc7</artifactId>
 <version>12.1.0.2</version>
</dependency>

回答by Jayen Chondigara

After executing

执行后

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar -DgeneratePom=true

check your .m2 repository folder (/com/oracle/ojdbc6/11.2.0.3) to see if ojdbc6.jar exists. If not check your maven repository settings under $M2_HOME/conf/settings.xml

检查您的 .m2 存储库文件夹 (/com/oracle/ojdbc6/11.2.0.3) 以查看 ojdbc6.jar 是否存在。如果没有检查 $M2_HOME/conf/settings.xml 下的 Maven 存储库设置

回答by Mohamed

Since Oracle is the licensed product, there are issue in adding maven dependency directly. To add any version of the ojdbc.jar, below 2 steps could do.

由于 Oracle 是许可产品,因此直接添加 maven 依赖项存在问题。要添加任何版本的 ojdbc.jar,以下 2 个步骤都可以做到。

  1. Run the below command to install ojdbc.jar into local maven repository.
  1. 运行以下命令将 ojdbc.jar 安装到本地 maven 存储库中。
/opt/apache-maven/bin/mvn install:install-file
    -Dfile=<path-to-file>/ojdbc7.jar
    -DgroupId=com.oracle
    -DartifactId=ojdbc7
    -Dversion=12.1.0.1.0
    -Dpackaging=jar

This will add the dependency into local repository.

这会将依赖项添加到本地存储库中。

  1. Now, add the dependency in the pom file
  1. 现在,在 pom 文件中添加依赖项
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>12.1.0.1.0</version>
</dependency>

回答by kuser699

I followed below command it worked:

我按照以下命令工作:

mvn install:install-file -Dfile=E:\JAVA\Spring\ojdbc14-10.2.0.4.0.jar\ojdbc14-10.2.0.4.0.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar

After installation check that jar is installed correctly on your M2_repo.

安装后检查 jar 是否正确安装在您的 M2_repo 上。

回答by Kiran P Fegade

Add Following dependency in pom.xml

在 pom.xml 中添加以下依赖项

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>oracle</artifactId>
    <version>10.2.0.2.0</version>
</dependency>