java 将 jar 上传到存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1912867/
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
upload jar to respository
提问by cometta
I have jar files that cannot be found on maven2 repository. I would like to add the jar so I can just include extra tag in my pom.xmlfile and other developer can use the jar. What are the steps needed to upload the jar to http webserver webfolder? What file should I uploaded beside custom.jar? What other files need to exist on the webfolder side by side with custom.jar?
我有在 maven2 存储库中找不到的 jar 文件。我想添加 jar,这样我就可以在我的pom.xml文件中包含额外的标签,其他开发人员可以使用该 jar。将 jar 上传到 http webserver webfolder 需要哪些步骤?我应该在custom.jar旁边上传什么文件?webfolder 中还需要与 custom.jar 并排存在哪些其他文件?
回答by Pascal Thivent
If you already have a web server set up pointing on a web folder, a simple way to deploy your custom JAR would to use the deploy:deploy-fileMojo. As documented in the Usagepage of the Maven Deploy Plugin:
如果您已经设置了指向 Web 文件夹的 Web 服务器,部署自定义 JAR 的一种简单方法是使用deploy:deploy-fileMojo。如Maven Deploy Plugin的Usage页面所述:
The
deploy:deploy-filemojo is used primarily for deploying artifacts to which were not built by Maven. The project's development team may or may not provide a POM for the artifact, and in some cases you may want to deploy the artifact to an internal remote repository. The deploy-file mojo provides functionality covering all of these use cases, and offers a wide range of configurability for generating a POM on-the-fly. Additionally, you can specify what layout your repository uses. The full usage statement of the deploy-file mojo can be described as:mvn deploy:deploy-file -Durl=file://C:\m2-repo \ -DrepositoryId=some.id \ -Dfile=your-artifact-1.0.jar \ [-DpomFile=your-pom.xml] \ [-DgroupId=org.some.group] \ [-DartifactId=your-artifact] \ [-Dversion=1.0] \ [-Dpackaging=jar] \ [-Dclassifier=test] \ [-DgeneratePom=true] \ [-DgeneratePom.description="My Project Description"] \ [-DrepositoryLayout=legacy] \ [-DuniqueVersion=false]
该
deploy:deploy-file魔咒主要用于部署于未通过的Maven构建文物。项目的开发团队可能会或可能不会为工件提供 POM,并且在某些情况下,您可能希望将工件部署到内部远程存储库。部署文件 mojo 提供了涵盖所有这些用例的功能,并为动态生成 POM 提供了广泛的可配置性。此外,您可以指定存储库使用的布局。deploy-file mojo 的完整使用说明可以描述为:mvn deploy:deploy-file -Durl=file://C:\m2-repo \ -DrepositoryId=some.id \ -Dfile=your-artifact-1.0.jar \ [-DpomFile=your-pom.xml] \ [-DgroupId=org.some.group] \ [-DartifactId=your-artifact] \ [-Dversion=1.0] \ [-Dpackaging=jar] \ [-Dclassifier=test] \ [-DgeneratePom=true] \ [-DgeneratePom.description="My Project Description"] \ [-DrepositoryLayout=legacy] \ [-DuniqueVersion=false]
Only the 3 first parameters are mandatory (short version). If you wonder what the repositoryIdis, the documentation of the Mojo says:
只有前 3 个参数是强制性的(简短版本)。如果你想知道repositoryId是什么,Mojo 的文档说:
Server Id to map on the
<id>under<server>section ofsettings.xmlIn most cases, this parameter will be required for authentication. Default value is: remote-repository.
要映射到
<id>下<server>部分的服务器 IDsettings.xml在大多数情况下,身份验证将需要此参数。默认值为:远程存储库。
In other words, the simplest way to use this would be to copy your custom JAR on the machine hosting the web server and to use the file://protocol when specifying the URL. There is no additional setup required. If you want to deploy remotely, then scp://is often the preferred protocol (there are others but this one is pretty easy to setup). Below, an example using scp:
换句话说,最简单的使用方法是在托管 Web 服务器的机器上复制您的自定义 JAR,并file://在指定 URL 时使用该协议。无需额外设置。如果你想远程部署,那么scp://通常是首选协议(还有其他协议,但这个很容易设置)。下面是一个使用 scp 的例子:
mvn deploy:deploy-file -DgroupId=my.group -DartifactId=myartifact -Dversion=1.0 \
-DgeneratePom=true \
-Dpackaging=jar \
-Dfile=custom.jar \
-DrepositoryId=some.id \
-Durl=scp://REMOTEMACHINE/PATH/TO/WEB_ROOT/maven2_repository
Actually, using a web server to host your own Maven repository is perfectly fine but it can be a bit painful to initialize. One solution to solve this issue is to use a Maven proxy (like Nexusfor example) instead of just a Maven repository. But this goes beyond your question.
实际上,使用 Web 服务器来托管您自己的 Maven 存储库非常好,但初始化可能有点痛苦。解决此问题的一种解决方案是使用 Maven 代理(例如Nexus)而不仅仅是 Maven 存储库。但这超出了你的问题。
For more resources on this, check (the principles are still valid even if the implementation solutions are a bit outdated):
有关这方面的更多资源,请检查(即使实施方案有点过时,原则仍然有效):
回答by Bozho
Preferably, you would need a local maven repository. One option for this is Nexus
最好,您需要一个本地 Maven 存储库。一种选择是Nexus
Or if you are working just yourself, you can save the overhead and put the jars in the repository on your machine - under home/.m2/repository, in an appropriate folder
或者,如果您只是自己工作,则可以节省开销并将 jars 放在您机器上的存储库中 - 在 下home/.m2/repository,在适当的文件夹中
回答by aholub7x
Next command helps to install the jar to the local repository. After this you can upload folder with the jar from local to the remote repository.
下一个命令有助于将 jar 安装到本地存储库。在此之后,您可以将带有 jar 的文件夹从本地上传到远程存储库。
mvn install:install-file \
-DgroupId=com.name \
-DartifactId=aaaa-bc \
-Dversion=1.0 \
-Dpackaging=jar \
-Dfile=aaaa-bc.jar \
-DcreateChecksum=true

