I have a jar files that cannot be found on maven2 repository. i interested to add the jar so i can just include extra tag in my pom.xml file and other developer can use the jar. what is 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
Preferably, you would need a local maven repository. One option for this is 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
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.
mvn install:install-file \
-DgroupId=com.name \
-DartifactId=aaaa-bc \
-Dversion=1.0 \
-Dpackaging=jar \
-Dfile=aaaa-bc.jar \
-DcreateChecksum=true
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:
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]
Only the 3 first parameters are mandatory (short version). If you wonder what the repositoryId is, the documentation of the Mojo says:
Server Id to map on the
<id>
under<server>
section ofsettings.xml
In most cases, this parameter will be required for authentication. Default value is: remote-repository.
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
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):