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

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

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

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


当前回答

Oracle JDBC驱动程序现在在Maven Central中可用。 链接如下:

Oracle JDBC驱动程序- Maven中心

Oracle开发人员的文章宣布了Oracle JDBC驱动程序在Maven Central的可用性:

Oracle宣布- Oracle JDBC驱动程序在Maven中心可用

例子:

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

其他回答

您可以使用Nexus来管理第三方依赖关系以及标准maven存储库中的依赖关系。

到目前为止,还不能使用maven存储库。我使用ivy作为依赖管理工具,但也使用了maven2的ibiblio存储库。这招对艾薇很管用

<dependency org="oracle" name="ojdbc14" rev="10.2.0.2" conf="*->default"/>

Maven2的依赖关系可能是这样的:

<dependency> 
    <groupId>oracle</groupId> 
    <artifactId>ojdbc14</artifactId> 
    <version>10.2.0.2</version> 
</dependency>

注意,我在ivy设置中定义了http://download.java.net/maven/2/和http://mirrors.ibiblio.org/pub/mirrors/maven/mule/dependencies/maven2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]作为maven2的外部回购。

截至今天(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>

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

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

解决了

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

需要启用这个存储库来查找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驱动程序的问题