Java pom.xml 中的 JDBC Maven 依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22946626/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 19:31:27  来源:igfitidea点击:

JDBC Maven Dependency in pom.xml

javaeclipsemavenjdbcpom.xml

提问by a.ras2002

I have created a Maven Project in Eclipse (EE Developer Kepler version) and I have in my pom.xml file the following error, "Missing artifact com.oracle:ojdbc7:jar:12.1.0.1" in this code

我在 Eclipse(EE Developer Kepler 版本)中创建了一个 Maven 项目,并且在我的 pom.xml 文件中出现了以下错误,“Missing artifact com.oracle:ojdbc7:jar:12.1.0.1” in this code

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc7</artifactId>
    <version>12.1.0.1</version>
</dependency>

I know that I have to add the jdbc repository into my .m2 folder. I have done so by downloading the ojdbc7.jar from the following link http://www.oracle.com/technetwork/database/features/jdbc/jdbc-drivers-12c-download-1958347.html

我知道我必须将 jdbc 存储库添加到我的 .m2 文件夹中。我通过从以下链接下载 ojdbc7.jar http://www.oracle.com/technetwork/database/features/jdbc/jdbc-drivers-12c-download-1958347.html

With that archive donwloaded, I open a terminal (I have Debian installed) and run the following command as root

下载该存档后,我打开一个终端(我安装了 Debian)并以 root 身份运行以下命令

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc7  
-Dversion=12.1.0.1 -Dpackaging=jar -Dfile=ojdbc7.jar -DgeneratePom=true

After that, I got as an output BUILD SUCCESS, and if I go to the .m2 folder I see in the com->oracle->ojdbc7two files called "ojdbc7-12.1.0.1.jar.lastUpdated" and "ojdbc7-12.1.0.1.pom.lastUpdated" but still Eclipse brings me the code into the pom.xml file as an error

在那之后,我得到了 BUILD SUCCESS 的输出,如果我转到 .m2 文件夹,我会在com->oracle->ojdbc7 中看到两个名为“ojdbc7-12.1.0.1.jar.lastUpdated”和“ojdbc7-12.1”的文件.0.1.pom.lastUpdated”,但 Eclipse 仍然将代码作为错误带入 pom.xml 文件

What can I do to fix this?

我能做些什么来解决这个问题?

采纳答案by robertoia

If you are using eclipse, go to the folder where you have your pom and try this commands:

如果您使用的是 eclipse,请转到您拥有 pom 的文件夹并尝试以下命令:

mvn -Declipse.workspace=<path-to-your-eclipse-workspace> eclipse:add-maven-repo
mvn eclipse:eclipse

I haven't tried it in Linux, but it should fix your dependencies / eclipse path issues.

我还没有在 Linux 中尝试过,但它应该可以解决您的依赖项/eclipse 路径问题。

回答by Alvin Thompson

  1. From the menu, select "Window-->Show View-->Other..."
  2. In the dialog, select "Maven-->Maven Repositories" and hit OK.
  3. In the Maven Repositories view, right-click "Local Repositories-->Local Repository" and select "Rebuild Index" from the popup menu. If asked if you're sure you want to rebuild the index, hit OK.
  1. 从菜单中选择“窗口-->显示视图-->其他...”
  2. 在对话框中,选择“Maven-->Maven Repositories”并点击OK。
  3. 在 Maven Repositories 视图中,右键单击“Local Repositories-->Local Repository”并从弹出菜单中选择“Rebuild Index”。如果询问您是否确定要重建索引,请点击“确定”。

If that doesn't work (it should), try right-clicking the project in the Explorer view, selecting "Maven-->Update Project..." from the popup menu, ensuring that "Update dependencies" is checked in the dialog that appears, and hitting OK.

如果这不起作用(应该),请尝试在资源管理器视图中右键单击项目,从弹出菜单中选择“Maven-->更新项目...”,确保在对话框中选中“更新依赖项”出现,然后点击确定。

BTW, you probably want to add <scope>runtime</scope>to your dependencyelement in the pom file, although that's not related to your issue.

顺便说一句,你可能要添加<scope>runtime</scope>到您dependency的POM文件中的元素,尽管这不相关的问题。

回答by Peter Gibbons

There is another choice for the Oracle JDBC drivers, that is not perfect, because it requires to be registered in the maven repository from Oracle, but it does not need the mvn install:install-file step.

Oracle JDBC 驱动程序还有另一种选择,它并不完美,因为它需要在 Oracle 的 maven 存储库中注册,但不需要 mvn install:install-file 步骤。

Check the steps to set it up here:

在此处检查设置步骤: