How to upload jar to respository?

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 \
                       -Dfile=your-artifact-1.0.jar \
                       [-DpomFile=your-pom.xml] \
                       [] \
                       [-DartifactId=your-artifact] \
                       [-Dversion=1.0] \
                       [-Dpackaging=jar] \
                       [-Dclassifier=test] \
                       [-DgeneratePom=true] \
                       [-DgeneratePom.description="My Project Description"] \
                       [-DrepositoryLayout=legacy] \

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 of settings.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 -DartifactId=myartifact -Dversion=1.0 \
  -DgeneratePom=true \
  -Dpackaging=jar \
  -Dfile=custom.jar \ \

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):

  • Using Maven in a corporate environment
  • Creating the repositories
  • Nexus Book: Repository Management with Nexus