简体   繁体   English

在Maven 1.1中为本地JAR添加依赖项

[英]Adding a dependency for a local JAR in Maven 1.1

My project is using maven 1.1, and I want to add a dependency for another JAR that I build which is located locally. 我的项目使用的是maven 1.1,我想为我构建的另一个位于本地的JAR添加依赖项。 How can I do this? 我怎样才能做到这一点?

You can add an entry in the pom.xml for that JAR and when you build the project using maven , just add the -o to the commmand. 您可以在pom.xml中为该JAR添加一个条目,并在使用maven生成项目时,只需将-o添加到命令中即可。 Make sure the JAR is present in the local m2 repository. 确保本地m2存储库中存在JAR

-o stands for offline, which means it'll look up for the dependencies in the local m2 only. -o表示离线,这意味着它将仅在本地m2查找依赖项。

将罐子安装到本地仓库

mvn install:install-file -Dfile=<path to your jar> -DgroupId=<groupID you want to give> -DartifactId=<artifactID you want to give> -Dversion=<version you want to give> -Dpackaging=jar

In my case I used the following strategy: install the file to your local repository and then add its dependency to your pom.xml. 在我的情况下,我使用以下策略:将文件安装到本地存储库,然后将其依赖项添加到pom.xml。

Installation could be done like follows: 安装可以如下进行:

mvn install:install-file \
  -DgroupId=my.local.jar \
  -DartifactId=localName \
  -Dpackaging=jar \
  -Dversion=1.0-MYVERSION \
  -Dfile=localFile.jar

for the installed file you would need the following dependency to your pom.xml 对于已安装的文件,您将需要以下对pom.xml的依赖

<dependency>
    <groupId>my.local.jar</groupId>
    <artifactId>localName</artifactId>
    <version>1.0-MYVERSION</version>
</dependency>

From maven-1.1 FAQ: 从maven-1.1常见问题解答:

How do I add a JAR from a non-Maven project to my local repository? 如何将非Maven项目中的JAR添加到本地存储库中?
If it is a JAR that cannot be uploaded to Maven's central repository because of a license, or it is private, you must manually copy it to your local repository. 如果它是一个JAR,由于许可证而无法上载到Maven的中央存储库,或者它是私有的,则必须手动将其复制到本地存储库。 After picking a sensible group ID, and making sure the filename is in the format artifactId-version.jar, copy it to ${maven.repo.local}/groupId/jars/artifactId-version.jar. 选择一个明智的组ID,并确保文件名格式为artifactId-version.jar后,将其复制到$ {maven.repo.local} /groupId/jars/artifactId-version.jar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM