Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle JDBC ojdbc6 Jar as a Maven Dependency

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?

like image 487
Marvo Avatar asked Mar 27 '12 22:03

Marvo


People also ask

What is ojdbc6 jar?

The "ojdbc6. jar" file constitutes the Oracle thin client-side JDBC driver which is compatible with Java 6 (JDBC level 4.0). For more information, read the Oracle JDBC FAQ. 1-Thereareacoupleofissuesthatmakecross-databasecompatibilitydifficulty.

How do I get ojdbc6 jar?

You will get those jars when installing the Oracle Client, the ojdbcX. jar files appear in ORACLE_HOME/jdbc/lib.


2 Answers

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' 
like image 171
Ondrej Kvasnovsky Avatar answered Sep 18 '22 08:09

Ondrej Kvasnovsky


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> 
like image 23
rickygrimes Avatar answered Sep 18 '22 08:09

rickygrimes