Oracle JDBC ojdbc6 Jar as a Maven Dependency

310,750

Solution 1

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

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.)

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

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

Solution 2

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 syntax:

<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:

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

Solution 3

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 -

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)

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 -

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

Solution 4

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,

Oracle JDBC ojdbc6 Jar as a Maven Dependency

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

Solution 5

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

if you download it to 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.

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

Related videos on Youtube

Marvo
Author by

Marvo

I'm a software engineer at the University of California. I work primarily in Java, but have coded in C, C++, ObjC, Python, Perl, Pascal, Z80, 370 Assembler, and probably a bunch of other languages I've long since forgotten.

Updated on June 18, 2021

Comments

  • Marvo
    Marvo about 3 years

    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.

    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

    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]
      

    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?

    • Raghuram
      Raghuram about 12 years
      Can you check if the file ojdbc6-11.2.0.3.jar is available in your local repository at the correct folder?
    • Marvo
      Marvo about 12 years
      The jar file never seems to get copied to the repository. Just a bunch of files that appear to reference it. Does the file need to be called exactly that? It's just ojdbc6.jar in my lib directory.
    • Raghuram
      Raghuram about 12 years
      Hmm! so mvn install:install-file has not worked. You should give absolute location of ojdbc6.jar or run the command from the folder that contains it. The file name is not a problem. You could run with a -X flag so that you can debug info.
    • nwinkler
      nwinkler about 12 years
      Is there any output when you run install-file? Maven should tell you where it installs the file to or whether there were any errors.
    • nwinkler
      nwinkler about 12 years
      As an unrelated note: You should look into using a repository mirror (something like Nexus, Artifactory, Archiva, ...). You could upload the file there and it would be available not only for you, but for everybody else using the same mirror too.
    • Marvo
      Marvo about 12 years
      I'm assuming putting Oracle's jars in someone else's repository would, at the very least, result in them taking them out, no? Otherwise, Oracle would host their jars in a repository like everyone else.
    • Marvo
      Marvo about 12 years
      Well, it appears that Raghuram had it: running the "mvn install" step from the directory where I was keeping the ojdbc6.jar. I had been saying -Dfile=~/lib/ojdb6.jar. When I cd'ed into the lib directory and ran the command from there, the jar file appeared in the repository. (In my example command in the original posting, I removed the reference to ~/lib/ to simplify my question.)
    • Marvo
      Marvo about 12 years
      Raghuram, if you'd like to make your response an answer, I'll gladly accept it. Thank you! And thanks everyone for the discussion that helped me diagnose this problem.
    • Marvo
      Marvo almost 12 years
      Returning a while later to report that my team did ultimate set up a local repository. I think we went with Artifactory or something like that.
  • Marvo
    Marvo over 11 years
    Ultimately that's what we did. We set up a repository here, and all of our projects now use it. I think it's useful to know how to do both, however.
  • Alden
    Alden over 10 years
    Is that lds.org repository legal? According to this answer it is illegal: stackoverflow.com/a/1074971/1415732
  • Ondrej Kvasnovsky
    Ondrej Kvasnovsky over 10 years
    I wonder, if I would install dependency to my company repository, would it be illegal too? Or only public repos are illegal? It is Oracle's fault that they do not have public Maven repository for their libraries. I would rather appreciate somebody is sharing that library in their repository (and it is constently accessible).
  • Ray Myers
    Ray Myers about 10 years
    Ondrej: In my understanding it's only illegal if the repository is public. My company hosts ojdbc in a private maven repo (artifactory) in just the way you suggest.
  • spiderman
    spiderman almost 10 years
    Thanks @Raghuram and Marvo
  • user12893298320392
    user12893298320392 almost 9 years
    Just a note: After following these steps, I still had the same error in eclipse until I performed Maven > Update Project. Then everything worked beautifully. This step might be obvious, but I figured I would add it.
  • phareim
    phareim almost 9 years
    ... to add to the "hello future reader post". this failed running powershell, but worked as expected running the ordinary windows CMD-shell. No powershell for you!
  • Quest Monger
    Quest Monger over 8 years
    for people trying to do this on windows, phareim's advice is gold. i got this working on windows 7 running maven 3.3.3 by typing the mvn command in command prompt. powershell kept throwing 'pom not found' error.
  • zb226
    zb226 about 8 years
    Of course it's "better" to add some arbitrary repo to your project, yeah. Wow, this is wrong on so many levels
  • Michael Shopsin
    Michael Shopsin about 8 years
    Maven is super picky about versions which aren't always easy to guess. Nice catch that the version is 11.2.0 not 11.2.0.3
  • Ben Madsen
    Ben Madsen almost 8 years
    @zb226: when that repository is internal and controlled by you or your organization, then yes, it is a very excellent idea.
  • zb226
    zb226 almost 8 years
    @BenMadsen: I can't seem to find the "internal" or "controlled by you (...)" parts in this answer. Apart from that, you're right of course. That's why I was talking about "some arbitrary" repo.
  • Marvo
    Marvo almost 8 years
    That's new since I asked the question. Nice!
  • Kailas
    Kailas about 7 years
    The order mentioned is important. I had added the dependency first then running the mvn intsall command, The error didn't disappear. Tried removing the dependency, save and then add it back again and save. All errors resolved (provided your project is set t "build automatically")
  • Pierluigi Vernetto
    Pierluigi Vernetto over 6 years
    great, however Oracle has a public Maven repository docs.oracle.com/middleware/1213/core/MAVEN/… , although you have to take extra (painful and totally unjustifiable ) steps to configure it
  • Gandalf
    Gandalf over 6 years
    Yeah, best use the mvn repo of a "trusted" church ;)
  • CJDownUnder
    CJDownUnder over 3 years
    Not sure how happy I'd be using the mormons' nexus server. Weird they have one though.
  • CJDownUnder
    CJDownUnder over 3 years
    For IntelliJ, make sure you File > Ivalidate Caches / Restart
  • CJDownUnder
    CJDownUnder over 3 years
    For Windows make sure you put all the values in quotes e.q. "com.oracle"
  • Marvo
    Marvo over 3 years
    Does that still require a password? I spent a month one afternoon trying to get that working with a password. And that didn't even account for needing to have it accessible from a build server.
  • Alisson Gomes
    Alisson Gomes over 3 years
    No, is public, configure maven dependency it's all.
  • Partha Paul
    Partha Paul over 2 years
    I have 2 folders in .m2: repository and wrapper exactly where should I paste the jar??