Java 将 maven 创建的 jar 文件安装到本地 repo

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

installing a jar file created by maven to local repo

javamaven

提问by Mr.Q

I ran the following command to install a custom jar in my local repository:

我运行以下命令在本地存储库中安装自定义 jar:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.1:install-file -Dfile=<path-to-file>

but when i try this:

但是当我尝试这个时:

mvn install:install-file -Dfile=E:\jarFiles\utill-1.0.jar -DlocalRepositoryPath=E:\repo

it gives me the following error:

它给了我以下错误:

The artifact information is incomplete or not valid:
[ERROR] [0]  'groupId' is missing.
[ERROR] [1]  'artifactId' is missin
[ERROR] [2]  'packaging' is missing
[ERROR] [3]  'version' is missing.

采纳答案by Abimaran Kugathasan

You have to provide those information (groupId, artifactId, packaging, version) too.

您也必须提供这些信息(groupId、artifactId、packaging、version)。

mvn install:install-file  -Dfile=path-to-your-artifact-jar \
                          -DgroupId=your.groupId \
                          -DartifactId=your-artifactId \
                          -Dversion=version \
                          -Dpackaging=jar \
                          -DgeneratePom=true

Check herefor more details

查看此处了解更多详情

回答by Sambhav Sharma

I think the error says it all. You dont even have to scratch your brain to get info out of it. It is a relevant error and straight to the point.

我认为错误说明了一切。您甚至不必动动脑子就可以从中获取信息。这是一个相关的错误,直截了当。

Refer: http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/

参考:http: //www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/

With your mvn installcommand, you need to provide groupID, artifactId, packaging and version. Check your pom for that information, from which you built the jar..

使用您的mvn install命令,您需要提供 groupID、artifactId、打包和版本。检查您的 pom 以获取该信息,您从中构建了 jar ..

Sample command:

示例命令:

mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar

mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar

回答by Mr.Q

Hi again guys i wanted to mention something, when i extracted the maven created jar file and copied the POM.xml file in a separate location and installed the jar file by referencing to it . it worked fine but i dont know why my first command din`t work! here is the command that worked;

嗨,伙计们,我想提一下,当我提取 maven 创建的 jar 文件并将 POM.xml 文件复制到单独的位置并通过引用它来安装 jar 文件时。它工作正常,但我不知道为什么我的第一个命令不起作用!这是有效的命令;

  mvn install:install-file -Dfile=E:\jarFiles\utill-1.0.jar -DpomFile=E:\jarFiles\pom.xml -DloaclRepositoryPath=E:\repo 

by the way obviously mvn install , also works fine and installs the jar file to my local repository.

顺便说一句,显然 mvn install 也可以正常工作并将 jar 文件安装到我的本地存储库。

回答by Vishal Kumar

This should work.

这应该有效。

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=<path-to-file>

回答by Sam West

I just had the same issue, and it was due to a corrupted jar file as suggested in the comments. I just replaced it and the command worked without any extra switches for groupid, packaging etc (because it was a maven jar already).

我刚刚遇到了同样的问题,这是由于评论中建议的 jar 文件已损坏。我只是替换了它,该命令在没有任何额外的 groupid、打包等开关的情况下工作(因为它已经是一个 Maven jar)。

It turned out that the jar was corrupted by pushing it from Windows to a git repo then pulling onto a Linux box. The solution was to tell get that jars are binaries to it didn't convert the line endings - see here: Jar file gets corrupted after pushing to github

事实证明,这个 jar 是通过将它从 Windows 推送到一个 git 存储库然后拉到一个 Linux 机器上而损坏的。解决方案是告诉 get jars 是二进制文件,它没有转换行尾 - 请参见此处:推送到 github 后 Jar 文件已损坏