问题描述
我有在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的简单方法是使用 deploy:deploy-file
Mojo.如Maven部署插件的用法页中所述:/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:
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:
换句话说,最简单的方法是在托管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):
- 在公司环境中使用Maven
- 创建存储库
- Nexus图书:使用Nexus进行存储库管理
这篇关于如何将jar上传到存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!