在Maven中添加依赖项 [英] Add a dependency in Maven

查看:249
本文介绍了在Maven中添加依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获取一个jar文件,并将其添加到maven 2中的依赖系统中?我将成为这个依赖关系的维护者,我的代码在类路径中需要这个jar,以便编译。

How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.

推荐答案

你我们必须分两步进行:

You'll have to do this in two steps:

如果您没有内部存储库,而您只是想添加JAR到您的本地存储库,您可以使用任意的groupId / artifactIds安装它:

If you don't have an internal repository, and you're just trying to add your JAR to your local repository, you can install it as follows, using any arbitrary groupId/artifactIds:

mvn install:install-file -DgroupId=com.stackoverflow... -DartifactId=yourartifactid... -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/jarfile

如果您有一个,您还可以将其部署到内部存储库,并希望将其提供给组织中的其他开发人员。我只是使用我的存储库的基于Web的界面来添加工件,但是您应该能够使用 mvn deploy:deploy-file ... 完成相同的操作。

You can also deploy it to your internal repository if you have one, and want to make this available to other developers in your organization. I just use my repository's web based interface to add artifacts, but you should be able to accomplish the same thing using mvn deploy:deploy-file ....

然后通过向元素添加以下内容来更新使用JAR的项目的pom.xml中的依赖关系:

Then update the dependency in the pom.xml of the projects that use the JAR by adding the following to the element:

<dependencies>
    ...
    <dependency>
        <groupId>com.stackoverflow...</groupId>
        <artifactId>artifactId...</artifactId>
        <version>1.0</version>
    </dependency>
    ...
</dependencies>

这篇关于在Maven中添加依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆