Java 如何将第三方 jar 添加到本地 Maven 存储库中?

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

How do I add third-party jars into local Maven repository?

javamavenjar

提问by Suzan Cioc

I have a library consisting of 4 jars:

我有一个由 4 个罐子组成的库:

matlabcontrol-4.1.0.jar
matlabcontrol-4.1.0-javadoc.jar
matlabcontrol-4.1.0-sources.jar
matlabcontrol-demo-4.1.0.jar

How do I add them to the local repository so that Maven knows where sources are and where javadoc is?

如何将它们添加到本地存储库,以便 Maven 知道源在哪里以及 javadoc 在哪里?

Documentation here http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.htmlis very brief and does not answer this question.

这里的文档http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html非常简短,没有回答这个问题。

回答by René Link

Classifiers can also be specified at the command-line. See http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#classifier.

分类器也可以在命令行中指定。请参阅http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#classifier

Javadoc and sources are just artifacts with a classifier of the same pom.

Javadoc 和源代码只是具有相同 pom 分类器的工件。

For example:

例如:

Install the main artifact

安装主工件

mvn install:install-file -Dfile=matlabcontrol-4.1.0.jar 
   -DgroupId=matlab -DartifactId=matlab -Dversion=4.1.0

Install the javadoc using the classifier javadoc:

使用分类器 javadoc 安装 javadoc:

 mvn install:install-file -Dfile=matlabcontrol-4.1.0.jar 
   -DgroupId=matlab -DartifactId=matlab -Dversion=4.1.0 -Dclassifier=javadoc

回答by Masudul

The documentation clearly mentioned the way. Think your matlabcontrol-4.1.0.jar in C:> location. So move your cmd on C:> location and run following command.

文档清楚地提到了方式。想想你的 matlabcontrol-4.1.0.jar 在 C:> 位置。因此,将您的 cmd 移动到 C:> 位置并运行以下命令。

mvn install:install-file -Dfile=matlabcontrol-4.1.0.jar -DgroupId=org.matlabcontrol \
    -DartifactId=matlabcontrol -Dversion=4.1.0 -Dpackaging=jar

If you do that, you can access your jar file with dependency, like:

如果这样做,您可以使用依赖项访问您的 jar 文件,例如:

 <dependency>
        <groupId>org.matlabcontrol</groupId>
        <artifactId>matlabcontrol</artifactId>
        <version>4.1.0</version>
 </dependency>