Java 在 Maven 存储库中查找 Oracle JDBC 驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1074869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find Oracle JDBC driver in Maven repository
提问by rperez
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:
我想将 oracle jdbc 驱动程序作为依赖项(运行时范围) - ojdbc14 添加到我的项目中。在 MVNrepository 站点中,放入 POM 的依赖项是:
<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:
当然这不起作用,因为它不在 maven 使用的中央存储库中。2个问题:
How do I find a repository (if any) that contains this artifact?
How do I add it so that Maven will use it?
如何找到包含此工件的存储库(如果有)?
我如何添加它以便 Maven 将使用它?
采纳答案by victor hugo
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.
不幸的是,由于二进制许可证,Oracle Driver JAR 没有公共存储库。这发生在许多依赖项中,但不是 Maven 的错。如果您碰巧找到包含 JAR 的公共存储库,您可以确定这是非法的。
How do I add it so that Maven will use it?
我如何添加它以便 Maven 将使用它?
Some JARs that can't be added due to license reasons have a pomentry in the Maven Central repo. Just check it out, it contains the vendor's preferred Maven info:
一些由于许可原因无法添加的 JAR在Maven Central repo 中有一个pom条目。只需检查一下,它包含供应商的首选 Maven 信息:
<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.
...以及下载文件的 URL,在本例中为 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):
下载 JAR 后,只需将其添加到您的计算机存储库中(注意我从 POM 中提取了 groupId、artifactId 和 version):
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
生成 POM 的最后一个参数将使您免于 pom.xml 警告
If your team has a local Maven repository this guidemight be helpful to upload the JAR there.
如果您的团队有本地 Maven 存储库,本指南可能有助于将 JAR 上传到那里。
回答by tugcem
Up to now, its not possible to use maven repositories. I'm using ivy as dependency management tool, but also use maven2' s ibiblio repositories. And this is working for ivy:
到目前为止,无法使用 maven 存储库。我使用 ivy 作为依赖管理工具,但也使用 maven2 的 ibiblio 存储库。这适用于常春藤:
<dependency org="oracle" name="ojdbc14" rev="10.2.0.2" conf="*->default"/>
Maven2' s dependency could be something like that:
Maven2 的依赖可能是这样的:
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.2</version>
</dependency>
Notice that i define http://download.java.net/maven/2/and http://mirrors.ibiblio.org/pub/mirrors/maven/mule/dependencies/maven2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]as external maven2 repos on my ivy settings.
请注意,我定义了http://download.java.net/maven/2/和http://mirrors.ibiblio.org/pub/mirrors/maven/mule/dependencies/maven2/[organisation]/[module]/[修订版]/[工件]-[修订版].[ext]作为我常春藤设置的外部 maven2 存储库。
回答by Michael Munsey
回答by Marvo
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.
我所做的是将 jar 包含在我的项目 (blech) 中,然后为其创建一个“系统”依赖项,指示 jar 的路径。这可能不是正确的方法,但它确实有效。它消除了团队中的其他开发人员(或设置构建服务器的人)将 jar 放在他们本地存储库中的需要。
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.
更新:当我运行 Hibernate Tools 时,这个解决方案对我有用。但是,它似乎不适用于构建 WAR 文件。它不包括目标 WAR 文件中的 ojdbc6.jar 文件。
1) Create a directory called "lib" in the root of your project.
1) 在项目的根目录中创建一个名为“lib”的目录。
2) Copy the ojdbc6.jar file there (whatever the jar is called.)
2) 将 ojdbc6.jar 文件复制到那里(无论 jar 叫什么。)
3) Create a dependency that looks something like this:
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>
Ugly, but works for me.
丑陋,但对我有用。
To include the files in the war file add the following to your pom
要将文件包含在 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>
回答by y?s??la
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"
有一个提供 jar 的 repo。在 SBT 中添加类似于此的解析器:“ http://dist.codehaus.org/mule/dependencies/maven2”中的“oracle driver repo ”
and a dependency: "oracle" % "ojdbc14" % "10.2.0.2"
和一个依赖项:“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/).
你可以用 maven 做同样的事情。pom.xml 和 jar 可用(http://dist.codehaus.org/mule/dependencies/maven2/oracle/ojdbc14/10.2.0.2/)。
回答by eckes
Some Oracle Products support publishing maven artifacts to a local repository. The products have a plugin/maven directory which contains descriptions where to find those artifacts and where to store them. There is a Plugin from Oracle which will actually do the upload.
某些 Oracle 产品支持将 Maven 工件发布到本地存储库。这些产品有一个 plugin/maven 目录,其中包含了在哪里可以找到这些工件以及在哪里存储它们的描述。有一个来自 Oracle 的插件实际上会进行上传。
See: http://docs.oracle.com/middleware/1212/core/MAVEN/config_maven.htm
请参阅:http: //docs.oracle.com/middleware/1212/core/MAVEN/config_maven.htm
One of the products which may ship OJDBC in this way is the WLS, it uses however quite strange coordinates:
可能以这种方式提供 OJDBC 的产品之一是 WLS,但它使用了非常奇怪的坐标:
<groupId>com.oracle.weblogic</groupId>
<artifactId>ojdbc6</artifactId>
<version>12.1.2-0-0</version>
回答by Peter Enis
Download the jar and place it in your project src/lib
. Now you can use the maven installer plugin.
下载 jar 并将其放入您的项目中src/lib
。现在您可以使用 maven 安装程序插件。
<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.
现在您只需要执行mvn clean
一次,oracle 库就安装在您的本地 maven 存储库中。
回答by taringamberini
1. How do I find a repository (if any) that contains this artifact?
1. 如何找到包含此工件的存储库(如果有)?
As DavidShas 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.
正如DavidS所评论的那样,我在回答时引用的行不再出现在我链接的当前(在我现在写作时)的 OTN 许可协议中。仅针对旧版本的工件(如 10.2.0.3.0 等)考虑此答案。
All Oracle Database JDBC Driversare distribuited under the OTN License Agreement.
所有Oracle 数据库 JDBC 驱动程序均根据OTN 许可协议分发。
If you read the OTN License Agreement you find this license term:
如果您阅读 OTN 许可协议,您会发现以下许可条款:
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.
所以这就是为什么你不能在任何公共 Maven 存储库中找到驱动程序的 jar 的原因,因为它会单独分发,如果发生了,它将违反许可证。
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:
(或任何更高版本)使 Maven 下载成为ojdbc14-10.2.0.3.0.pom
唯一的,并且在该 pom 中您可以阅读:
...
<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.
它会通知您有关 OTN 许可证的信息。
2. How do I add it so that Maven will use it?
2. 如何添加它以便Maven 使用它?
In order to make the above dependency works I agree with victor hugowho were suggesting you hereto manually install the jar into your local Maven repository (the .m2
directory) by running:
为了使上述依赖项起作用,我同意victor hugo 的意见,他在这里建议您.m2
通过运行以下命令将 jar 手动安装到本地 Maven 存储库(目录)中:
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 abovedoesn't limit only where you can't find the JDBC jar, but it limits where you install it too!
但我想补充一点,上面的许可条款不仅限制了您找不到 JDBC jar 的位置,而且还限制了您安装它的位置!
In fact your local Maven repository must be private and not sharedbecause 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.
事实上,您的本地 Maven 存储库必须是私有的而不是共享的,因为如果它被共享,它将是一种单独分发 jar 的分发,即使是一小群人进入您的局域网,这代表了违反 OTN 许可协议。
Moreover I think you should avoid installing the JDBC jar in your corporation repository manager(such as Artifactoryor 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.
此外,我认为您应该避免在您的公司存储库管理器(例如Artifactory或Nexus)中将 JDBC jar作为单个工件安装,因为如果安装了它,它仍然会单独分发,即使仅分发给您组织中的人员,这代表一个OTN许可协议违反。
回答by Makarand
SOLVED
解决了
- Please do following settings to resolve the error
- 请执行以下设置以解决错误
This repository needs to be enable for finding Oracle 10.0.3.0 dependecies (this setting needs to be done in Buildconfig.groovy grails.project.dependency.resolver = "ivy" // or ivy
需要启用此存储库以查找 Oracle 10.0.3.0 依赖项(此设置需要在 Buildconfig.groovy grails.project.dependency.resolver = "ivy" // 或 ivy
Also use following setting for compile time Oracle driver download
还使用以下设置进行编译时 Oracle 驱动程序下载
runtime "com.oracle:ojdbc:10.2.0.3.0"
运行时“com.oracle:ojdbc:10.2.0.3.0”
This should solve your issue for not finding the Oracle driver for grails application
这应该可以解决您找不到 grails 应用程序的 Oracle 驱动程序的问题
回答by searching9x
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>