Find Oracle JDBC driver in Maven repository

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:

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

of course this does't work as it is not in the central repository used by maven. 2 questions:

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

  • How do I add it so that Maven will use it?


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

    Unfortunately due the binary license there is no public repository with the Oracle Driver JAR. This happens with many dependencies but is not Maven's fault. If you happen to find a public repository containing the JAR you can be sure that is illegal.

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

    Some JARs that can't be added due to license reasons have a pom entry in the Maven Central repo. Just check it out, it contains the vendor's preferred Maven info:

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

    ...and the URL to download the file which in this case is http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html.

    Once you've downloaded the JAR just add it to your computer repository with (note I pulled the groupId, artifactId and version from the POM):

    mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 
         -Dversion=10.2.0.3.0 -Dpackaging=jar -Dfile=ojdbc.jar -DgeneratePom=true
    

    The last parameter for generating a POM will save you from pom.xml warnings

    If your team has a local Maven repository this guide might be helpful to upload the JAR there.


    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>
    

    Download the jar and place it in your project src/lib . Now you can use the maven installer plugin.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
            <execution>
                <id>install-oracle-jdbc</id>
                <goals>
                    <goal>install-file</goal>
                </goals>
                <phase>clean</phase>
                <configuration>
                    <groupId>com.oracle</groupId>
                    <artifactId>ojdbc6</artifactId>
                    <version>11.2.0</version>
                    <packaging>jar</packaging>
                    <generatePom>true</generatePom>
                    <createChecksum>true</createChecksum>
                    <file>${project.basedir}/src/lib/ojdbc6.jar</file>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    Now you only have to execute mvn clean once and the oracle lib is installed in your local maven repository.

    链接地址: http://www.djcxy.com/p/73828.html

    上一篇: 构建路径指定执行环境J2SE

    下一篇: 在Maven存储库中查找Oracle JDBC驱动程序