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

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

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

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


当前回答

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>

其他回答

如果你正在使用Netbeans,转到Dependencies并手动安装artifact。找到你下载的.jar文件就完成了。清洁构建将解决任何问题。

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

相反,我所做的是将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>

这对我来说很有魅力。我尝试了很多方法,但这个方法帮了我。 确保遵循每个步骤并将XML文件命名为完全相同的名称。

https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides

这个过程有点乏味,但确实有效。

试一试:

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

在我的情况下,在添加下面的版本依赖项(10.2.0.4)后,它就可以工作了。在添加这个10.2.0.3.0版本后,由于.jar文件无法在存储库路径中使用而无法工作。

<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4</version>