Find Oracle JDBC driver in Maven repository

前端 未结 22 1413
你的背包
你的背包 2020-11-22 09:28

I want to add the oracle jdbc driver to my project as dependency (runtime scope) - ojdbc14. In MVNrepository site the dependency to put in the POM is:



        
相关标签:
22条回答
  • 2020-11-22 10:11

    1. How do I find a repository (if any) that contains this artifact?

    As DavidS has commented the line I quoted at the time I answered is no longer present in the current (at the time I'm writing now) OTN License Agreement agreement I linked. Consider this answer only for older version of the artifact, as the 10.2.0.3.0 and the like.

    All Oracle Database JDBC Drivers are distribuited under the OTN License Agreement.

    If you read the OTN License Agreement you find this license term:

    You may not:
    ...
    - distribute the programs unless accompanied with your applications;
    ...

    so that's why you can't find the driver's jar in any public Maven Repository, because it would be distributed alone, and if it happened it would be a license violation.

    Adding the dependency:

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc14</artifactId>
        <version>10.2.0.3.0</version>
    </dependency>
    

    (or any later version) make Maven downloads the ojdbc14-10.2.0.3.0.pom only, and in that pom you can read:

    ...
    <licenses>
        <license>
            <name>Oracle Technology Network Development and Distribution License Terms</name>
            <url>http://www.oracle.com/technology/software/htdocs/distlic.html</url>
        </license>
    </licenses>
    ...
    

    which informs you about the OTN License.

    2. How do I add it so that Maven will use it?

    In order to make the above dependency works I agree with victor hugo who were suggesting you here to manually install the jar into your local Maven repository (the .m2 directory) by running:

    mvn install:install-file -Dfile={Path_to_your_ojdbc.jar} -DgroupId=com.oracle 
    -DartifactId=ojdbc -Dversion=10.2.0.3.0 -Dpackaging=jar
    

    but I want to add that the license term above doesn't limit only where you can't find the JDBC jar, but it limits where you install it too!

    In fact your local Maven repository must be private and not shared because if it was shared it would be a kind of distribution in which the jar is distributed alone, even if to a little group of people into your local area network, and this represent a OTN License Agreement violation.

    Moreover I think you should avoid installing the JDBC jar in your corporation repository manager (such as Artifactory or Nexus) as a single artifact because if it was installed it would be still distributed alone, even if to people in your organization only, and this represents a OTN License Agreement violation.

    0 讨论(0)
  • 2020-11-22 10:15

    Good news everyone! Finally we can use Oracle's official repo: https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides

    0 讨论(0)
  • 2020-11-22 10:15

    There is one repo that provides the jar. In SBT add a resolver similar to this: "oracle driver repo" at "http://dist.codehaus.org/mule/dependencies/maven2"

    and a dependency: "oracle" % "ojdbc14" % "10.2.0.2"

    You can do the same with maven. pom.xml and jar are available (http://dist.codehaus.org/mule/dependencies/maven2/oracle/ojdbc14/10.2.0.2/).

    0 讨论(0)
  • 2020-11-22 10:19

    For whatever reason, I could not get any of the above solutions to work. (Still can't.)

    What I did instead was to include the jar in my project (blech) and then create a "system" dependency for it that indicates the path to the jar. It's probably not the RIGHT way to do it, but it does work. And it eliminates the need for the other developers on the team (or the guy setting up the build server) to put the jar in their local repositories.

    UPDATE: This solution works for me when I run Hibernate Tools. It does NOT appear to work for building the WAR file, however. It doesn't include the ojdbc6.jar file in the target WAR file.

    1) Create a directory called "lib" in the root of your project.

    2) Copy the ojdbc6.jar file there (whatever the jar is called.)

    3) Create a dependency that looks something like this:

    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc</artifactId>
        <version>14</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/ojdbc6.jar</systemPath> <!-- must match file name -->
    </dependency>
    

    Ugly, but works for me.

    To include the files in the war file add the following to your pom

    <build>
        <finalName>MyAppName</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${basedir}/src/main/java</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <includes>
                                <include>**/*.properties</include>
                                <include>**/*.xml</include>
                                <include>**/*.css</include>
                                <include>**/*.html</include>
                            </includes>
                        </resource>
                        <resource>
                            <directory>${basedir}/lib</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
    
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    0 讨论(0)
  • 2020-11-22 10:20

    The Oracle JDBC drivers are now available in Maven Central. Here is the Link:

    Oracle JDBC Drivers - Maven Central

    Oracle developers article announcing the availability of the Oracle JDBC drivers in Maven Central:

    Oracle announcing - Oracle JDBC drivers available in Maven Central

    Example:

    <!-- https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc10 -->
    <dependency>
       <groupId>com.oracle.database.jdbc</groupId>
       <artifactId>ojdbc10</artifactId>
       <version>19.3.0.0</version>
    </dependency>
    
    0 讨论(0)
  • 2020-11-22 10:21

    Try with:

    <repositories>
        <!-- Repository for ORACLE ojdbc6. -->
        <repository>
            <id>codelds</id>
            <url>https://code.lds.org/nexus/content/groups/main-repo</url>
        </repository>
    </repositories>
    <dependencies> 
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3</version>
        </dependency>
    </dependencies> 
    
    0 讨论(0)
提交回复
热议问题