如何在 Eclipse 中添加 Maven 依赖项?
我根本不知道如何使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
事实上,当您打开 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.
您需要使用 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.
打开 pom.xml 文件。
在
project
标签下添加
作为另一个标签,然后通过 google 查找 Maven 依赖项。我使用 this 进行搜索。因此,在获取依赖项后,在
标签内创建另一个标签dependency
。所以最终它会看起来像这样。
希望有帮助。
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.
Hope it helps.
我也遇到过类似的问题,并通过将丢失的 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.
我在 Maven 依赖项上遇到了同样的问题,例如:不幸的是,你的 Maven 依赖项从你的构建路径中删除了,然后你会遇到很多异常,如果你按照下面的过程,你可以轻松解决这个问题。
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.