我想添加oracle jdbc驱动程序到我的项目作为依赖(运行时范围)- ojdbc14。 在MVNrepository站点中,要放在POM中的依赖项是:

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

当然,这是行不通的,因为它不在maven使用的中央存储库中。 两个问题:

我如何找到包含此工件的存储库(如果有的话)? 如何添加它以便Maven使用它?


当前回答

你可以在这里找到一个在Maven项目上使用Oracle JDBC驱动程序的Github简单示例项目。

您可以找到持续集成的所有解释+一个示例,并在Travis-CI上运行。

DEMO

pom.xml

<properties>
    <oracle.driver.version>12.2.0.1</oracle.driver.version>
</properties>

<repositories>
    <repository>
        <id>maven.oracle.com</id>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>https://maven.oracle.com</url>
        <layout>default</layout>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>maven.oracle.com</id>
        <url>https://maven.oracle.com</url>
    </pluginRepository>
</pluginRepositories>

<dependencies>
    <dependency>
        <groupId>com.oracle.jdbc</groupId>
        <artifactId>ojdbc8</artifactId>
        <version>${oracle.driver.version}</version>
    </dependency>
</dependencies>

mvnsettings.xml

<settings>
    <servers>
        <server>
            <id>maven.oracle.com</id>
            <username>${OTN_USERNAME}</username>
            <password>${OTN_PASSWORD}</password>
            <configuration>
                <basicAuthScope>
                    <host>ANY</host>
                    <port>ANY</port>
                    <realm>OAM 11g</realm>
                </basicAuthScope>
                <httpConfiguration>
                    <all>
                        <params>
                            <property>
                                <name>http.protocol.allow-circular-redirects</name>
                                <value>%b,true</value>
                            </property>
                        </params>
                    </all>
                </httpConfiguration>
            </configuration>
        </server>
    </servers>
</settings>

如何在当地环境中使用

在test/mvnsettings.xml文件中修改${OTN_USERNAME

在test/mvnsettings.xml文件中修改Oracle密码${OTN_PASSWORD}

mvn clean install --settings test/mvnsettings.xml

其他回答

无论出于何种原因,我都无法让上述任何解决方案发挥作用。(仍然不能)。

相反,我所做的是将jar包含在我的项目中(blech),然后为它创建一个“系统”依赖项,指示jar的路径。这可能不是正确的方法,但确实有效。并且它消除了团队中的其他开发人员(或设置构建服务器的人员)将jar放在本地存储库中的需要。

更新:当我运行Hibernate工具时,此解决方案适用于我。但是,它似乎不能用于构建WAR文件。它不包括目标WAR文件中的ojdbc6.jar文件。

1)在项目的根目录下创建一个名为“lib”的目录。

2)复制ojdbc6.jar文件(不管这个jar叫什么)。

3)创建一个依赖项,看起来像这样:

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

丑,但对我有用。

要在war文件中包含这些文件,请将以下内容添加到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>

截至今天(2020年2月27日),Oracle宣布它已经在Maven Central上发布了从版本11.2.0.4(例如ojdbc6)到19.3.0(例如ojdbc10)的所有JDBC客户端库,组id为com.oracle.database:

例子:

<dependency>
  <groupId>com.oracle.database.jdbc</groupId>
  <artifactId>ojdbc10</artifactId>
  <version>19.3.0.0</version>
</dependency>

解决了

请执行以下设置以解决错误

需要启用这个存储库来查找Oracle 10.0.3.0依赖项(这个设置需要在Buildconfig.groovy中完成 Grails.project.dependency.resolver = "ivy" //或ivy

在编译时下载Oracle驱动程序时也使用以下设置

runtime com.oracle: ojdbc 10.2.0.3.0 "

这将解决您找不到grails应用程序的Oracle驱动程序的问题


Oracle现在在maven.oracle.com上公开maven存储库 但是,您需要进行身份验证。

参见https://blogs.oracle.com/WebLogicServer/entry/weblogic_server_and_the_oracle

根据博客文章中的评论,ojdbc驱动程序应该在以下坐标处可用:

<groupId>com.oracle.weblogic</groupId>
 <artifactId>ojdbc7</artifactId>
 <version>12.1.3-0-0</version>
 <packaging>jar</packaging>

大家好!最后,我们可以使用甲骨文的官方回购: https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides