如何在 Eclipse 中添加 Maven 依赖项?

发布于 2025-01-03 03:42:51 字数 759 浏览 0 评论 0原文

我根本不知道如何使用Maven。我已经使用 Eclipse 进行开发几年了,但还不需要了解它。但是,现在我正在查看一些文档 建议我执行以下操作:

“要将其包含在您的项目中,只需将此 Maven 依赖项添加到您的构建中。”

<repository>
   <id>jboss</id>
   <url>http://repository.jboss.org/maven2</url>
</repository>

   ...
<dependency>
   <groupId>org.jboss.resteasy</groupId>
   <artifactId>resteasy-jackson-provider</artifactId>
   <version>1.1.GA</version>
</dependency>

我如何在我的 Eclipse 项目中执行此操作?

请假设我对 Maven 一无所知。我刚刚发现它可以通过在命令行上输入 mvn 来安装在我的计算机上,但这确实是我的知识范围。如果有一种等效的非 Maven 方法可以使用 Eclipse 遵循这些说明,我会很高兴继续对 Maven 一无所知。

I don't know how to use Maven at all. I've been developing for a couple years with Eclipse and haven't yet needed to know about it. However, now I'm looking at some docs that suggest I do the following:

"To include it within your project, just add this maven dependency to your build."

<repository>
   <id>jboss</id>
   <url>http://repository.jboss.org/maven2</url>
</repository>

   ...
<dependency>
   <groupId>org.jboss.resteasy</groupId>
   <artifactId>resteasy-jackson-provider</artifactId>
   <version>1.1.GA</version>
</dependency>

How do I do this with my Eclipse project?

Please assume I know nothing about Maven. I just figured out it might be installed on my computer by typing mvn on the command line, but that's seriously the extent of my knowledge. I would be happy to continue knowing nothing about Maven if there is an equivalent, non-Maven way of following these instructions with Eclipse.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

吃→可爱长大的 2025-01-10 03:42:51
  1. 在顶部菜单栏上,打开窗口->显示视图->其他
  2. 在 Show View 窗口中,打开 Maven -> Maven 存储库

Show View - Maven Repositories

  1. 在出现的窗口中,右键单击 Global Repositories 并选择Go Into
  2. 右键单击​​“<强>中央(http://repo.maven.apache.org/maven2)”并选择“< strong>重建索引”
  • 注意,完成下载需要很长时间!!!
  1. 一旦索引完成,右键单击该项目->; Maven -> 添加依赖项并开始输入要导入的项目的名称(例如“hibernate”)。
  • 搜索结果将自动填充到下面的“搜索结果”框中。
  1. On the top menu bar, open Window -> Show View -> Other
  2. In the Show View window, open Maven -> Maven Repositories

Show View - Maven Repositories

  1. In the window that appears, right-click on Global Repositories and select Go Into
  2. Right-click on "central (http://repo.maven.apache.org/maven2)" and select "Rebuild Index"
  • Note that it will take very long to complete the download!!!
  1. Once indexing is complete, Right-click on the project -> Maven -> Add Dependency and start typing the name of the project you want to import (such as "hibernate").
  • The search results will auto-fill in the "Search Results" box below.
梨涡 2025-01-10 03:42:51

事实上,当您打开 pom.xml 时,您应该在底部看到 5 个选项卡。单击 pom.xml,您可以键入所需的任何依赖项。

输入图像描述这里

In fact when you open the pom.xml, you should see 5 tabs in the bottom. Click the pom.xml, and you can type whatever dependencies you want.

enter image description here

玩物 2025-01-10 03:42:51

您需要使用 Eclipse 的 Maven 插件才能正确执行此操作。 m2e 插件内置于最新版本的 Eclipse 中,并且在将 Maven 集成到 IDE 方面做得不错(即使不是完美)。您需要将项目创建为“Maven 项目”。或者,您可以将现有的 Maven POM 导入工作区以自动创建项目。在 IDE 中创建 Maven 项目后,只需打开 POM 并向其添加依赖项即可。

现在,如果您没有适用于 Eclipse 的 Maven 插件,则需要获取相关依赖项的 jar,并手动将它们添加为项目的类路径引用。这可能会让人不愉快,因为您不仅需要顶级 JAR,还需要它的所有依赖项。

基本上,我建议您为 Eclipse 获取一个不错的 Maven 插件,并让它为您处理依赖项管理。

You need to be using a Maven plugin for Eclipse in order to do this properly. The m2e plugin is built into the latest version of Eclipse, and does a decent if not perfect job of integrating Maven into the IDE. You will want to create your project as a 'Maven Project'. Alternatively you can import an existing Maven POM into your workspace to automatically create projects. Once you have your Maven project in the IDE, simply open up the POM and add your dependency to it.

Now, if you do not have a Maven plugin for Eclipse, you will need to get the jar(s) for the dependency in question and manually add them as classpath references to your project. This could get unpleasant as you will need not just the top level JAR, but all its dependencies as well.

Basically, I recommend you get a decent Maven plugin for Eclipse and let it handle the dependency management for you.

怀里藏娇 2025-01-10 03:42:51

打开 pom.xml 文件。

project 标签下添加 作为另一个标签,然后通过 google 查找 Maven 依赖项。我使用 this 进行搜索。

因此,在获取依赖项后,在 标签内创建另一个标签 dependency

所以最终它会看起来像这样。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>doc-examples</groupId>
  <artifactId>lambda-java-example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>lambda-java-example</name>
  <dependencies>
      <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-lambda-java-core</artifactId>
        <version>1.0.0</version>
    </dependency>
  </dependencies>
</project>

希望有帮助。

Open the pom.xml file.

under the project tag add <dependencies> as another tag, and google for the Maven dependencies. I used this to search.

So after getting the dependency create another tag dependency inside <dependencies> tag.

So ultimately it will look something like this.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>doc-examples</groupId>
  <artifactId>lambda-java-example</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>lambda-java-example</name>
  <dependencies>
      <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-lambda-java-core</artifactId>
        <version>1.0.0</version>
    </dependency>
  </dependencies>
</project>

Hope it helps.

岁月蹉跎了容颜 2025-01-10 03:42:51

我也遇到过类似的问题,并通过将丢失的 Jar 文件复制到 .M2 路径来修复,

例如:如果您看到错误消息为 Missing artifact tws:axis-client:jar:8.7 那么您必须下载“axis-client-8.7.jar”文件并将其粘贴到以下位置才能解决问题。

C:\Users\UsernameXXX.m2\repository\tws\axis-client\8.7(粘贴 axis-client-8.7.jar)。

最后,右键单击项目->Maven->更新项目...就是这样。

快乐编码。

I have faced the similar issue and fixed by copying the missing Jar files in to .M2 Path,

For example: if you see the error message as Missing artifact tws:axis-client:jar:8.7 then you have to download "axis-client-8.7.jar" file and paste the same in to below location will resolve the issue.

C:\Users\UsernameXXX.m2\repository\tws\axis-client\8.7(Paste axis-client-8.7.jar).

finally, right click on project->Maven->Update Project...Thats it.

happy coding.

泪意 2025-01-10 03:42:51

我在 Maven 依赖项上遇到了同样的问题,例如:不幸的是,你的 Maven 依赖项从你的构建路径中删除了,然后你会遇到很多异常,如果你按照下面的过程,你可以轻松解决这个问题。

右键单击项目>> maven >> updateProject >> selectProject >> OK

I have faced same problem with maven dependencies, eg: unfortunetly your maven dependencies deleted from your buildpath,then you people get lot of exceptions,if you follow below process you can easily resolve this issue.

 Right click on project >> maven >> updateProject >> selectProject >> OK

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文