如何将jar上传到存储库? [英] How to upload jar to respository?

查看:94
本文介绍了如何将jar上传到存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在Maven Central存储库中找不到的jar文件.我想添加jar,这样我就可以在我的 pom.xml 文件中添加额外的标签,其他开发人员可以使用jar.将jar上载到http webserver webfolder需要执行哪些步骤?我应该在 custom.jar 旁边上传什么文件?

custom.jar 还需要在web文件夹中并排放置哪些其他文件?

I have jar files that cannot be found on Maven Central repository. I would like to add the jar so I can just include extra tag in my pom.xml file 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?

推荐答案

如果您已经设置了指向Web文件夹的Web服务器,则部署自定义JAR的简单方法是使用用法页中所述:/p>

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-file Mojo. As documented in the Usage page of the Maven Deploy Plugin:

使用了 deploy:deploy-file mojo主要用于将工件部署到不是由Maven建造的.这项目的开发团队可能会或可能会没有为工件提供POM,在某些情况下,您可能想要将工件部署到内部远程存储库.部署文件mojo提供功能覆盖所有这些用例,并提供了广泛的可配置性即时生成POM.此外,您可以指定布局存储库使用的布局.完整的部署文件的使用说明mojo可以描述为:

The deploy:deploy-file mojo 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]

只有前三个参数是必需的(简短版本).如果您想知道 repositoryId 是什么,,Mojo的文档说:

Only the 3 first parameters are mandatory (short version). If you wonder what the repositoryId is, the documentation of the Mojo says:

在大多数情况下,此参数会映射到 settings.xml < server> 部分下的< id> 上的

Server ID将需要进行身份验证.默认值为:远程存储库.

Server Id to map on the <id> under <server> section of settings.xml In most cases, this parameter will be required for authentication. Default value is: remote-repository.

换句话说,最简单的方法是在托管Web服务器的计算机上复制自定义JAR,并在指定URL时使用 file://协议.无需其他设置.如果要远程部署,则 scp://通常是首选协议(虽然还有其他协议,但该协议很容易设置).下面是使用scp的示例:

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:

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

实际上,使用Web服务器托管您自己的Maven存储库是完全可以的,但初始化起来可能会有些痛苦.解决此问题的一种解决方案是使用Maven代理(例如,例如 Nexus ),而不是仅使用Maven存储库.但这超出了您的问题.

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 Nexus for example) instead of just a Maven repository. But this goes beyond your question.

有关更多资源,请检查(即使实施解决方案有些过时,原则仍然有效):

For more resources on this, check (the principles are still valid even if the implementation solutions are a bit outdated):

这篇关于如何将jar上传到存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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