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?
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 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 -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):
Using Maven in a corporate environment
Creating the repositories
Nexus Book: Repository Management with Nexus
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
Related
As jitpack.io has been down for almost two days now, I am trying to migrate the jars to different repository.
I took the local jars of the required libraries and deployed them with mvn deployfile:
mvn deploy:deploy-file \
-DgroupId=com.github.dmurph \
-DartifactId=jgoogleanalyticstracker \
-Dversion=69f68caf8e \
-Dpackaging=jar \
-Dfile=jgoogleanalyticstracker-master-69f68caf8e-1.jar \
-Durl=https://gitlab.com/api/v4/projects/{your-project-id}/packages/maven \
-DrepositoryId=gitlab-maven
This is great and I can see the jars being deployed and I can link to them.
However it seems that any dependencies for the original library are ignored and when trying to use this I am getting a lot of Class not found exceptions of the related dependencies.
Is there a way to publish the jar with correct links to dependencies?
How does my firm get a jar into a maven repo so maven projects can access it from inhouse.
Can someone please point me to a good step by step details on how to do the following
Make a jar with Maven
Get the jar installed into a local maven repo
I doubt your company wants their private internal code hosted on a public repository:
Install your own repository server inside your own network, I use Archiva. This is the most ideal solution, then you can set up Mavenized projects to automatically upload themselves to your private repository when you do mvn:release and everyone will see the new versions. How to use Archiva is all very well documented.
If they have open source code that want to share, that is different:
You can publish public facing open source code through Sonatype.
If you just want to install a dependency to a local repository:
If you just want to install a .jar locally that is easy and well documented.
mvn install:install-file -Dfile=path-to-your-artifact-jar \
-DgroupId=your.groupId \
-DartifactId=your-artifactId \
-Dversion=version \
-Dpackaging=jar
I need to know if having a Maven project, I can import external (*.jar)'s without generating a Maven dependency (POM), just importing them in the project build path.
I'm finding troubles trying to run the project when it asks me for other dependencies that I'm no able to find in the web, and I have checked that those dependencies are not necessary because I checked my code and the (*.jar)'s in a project which doesn't use Maven and it works (without the necessity of importing that libs).
You can import a jar to your local repository and reference it in the POM as usual. However, every developer needs to do the import on his/her machine (once).
see: http://jeff.langcode.com/archives/27
You need to use the goal on maven-install-plugin: install-file:
mvn install:install-file -Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-Dsources=src.jar] \
[-Djavadoc=apidocs.jar] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=sources] \
[-DgeneratePom=true] \
[-DcreateChecksum=true]
If you are using Nexus, you can upload the jar manually.
Disclaimer: the following is only applicable when working in an environment where multiple people will share the same project. If you're on your own then all that has been suggested is just fine.
I'm not fond of system dependencies or doing local imports; in both cases you're still managing dependencies per machine and that is a burden Maven should be taking away from you.
If you really have a dependency that cannot be found in any online Maven repository, I would rather take the hard but more dependable route and that is to install a local Nexus server, which you can then also setup as a nice mirror for Maven central and the JBoss Nexus so clients don't have to keep downloading dependencies off of the internet. That way you have a single machine where all your Maven dependencies are maintained, which makes it nice and controllable. Plus your Nexus is more readily available; an external Maven source may go down or become unavailable should your internet connection drop.
You can then install your jars in the Nexus (in a local repository called 'third-party' is a common strategy I have seen used in the companies I have worked for so far) and your Maven clients, if properly told that your Nexus server is a mirror, can reference the third-party Maven dependencies as if they are coming from an online one.
You can provide a System Dependency.
I'm using the following command to create a local repository within my project (used on many systems so I was experimenting a bit with having a local maven repository inside my project folder for storing external jars that can't be found on any online repository):
C:\Users\someone\workspace\someProject>mvn install:install-file
-Dfile=somePackage-1.0.0.jar
-DgroupId=foo.bar
-DartifactId=somePackage
-Dversion=1.0.0
-Dpackaging=jar
-DlocalRepositoryPath=libs
-DcreateChecksum=true
This is run from Windows command line. Somehow, even with -DlocalRepositoryPath, it's still installing the jar into the default local repository (C:\Users\someone\.m2\, etc.). What am I doing wrong here? I tried different variations of the libs path, like /libs, /libs/, full path, using "", but nothing worked. Why isn't the -DlocalRepositoryPath argument not working here? I'm using Maven 2.2.1.
The install:install-file option ignores the localRepositoryPath when using the version 2.2 of the plugin. However, it works with version 2.3 and higher.
Also, try using the fully qualified name of the plugin to specify the version:
mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file \
-Dfile=<path-to-your-file> -DgroupId=<myGroup> \
-DartifactId=<myArtifactId> -Dversion=<myVersion> \
-Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>
Some 3rd party JAR files are not found in the public maven repository. To use them, do I need to manully add them to the local repository? Any steps to do it?
You can define a minimal pom for each jar and install them into the local repository. There's even a guide for it.
The command (copied and pasted from the guide) is:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Aside from the answer of Aleksi you can also introduce a maven proxy, like Nexus or artifactory.
These tools are accessed by maven (if so configured) to get the artifacts, and they in turn download them when required. With such a tool in place your local maven need only know about a single location, and the Nexus or Artifactory can map a series of internet repositories to a single "virtual" one. You can of course upload your own artifacts too.
If you're developing on your own with a fast internet connection it might be a bit overkill though.
If you're in an enterprise setting I'd recommend Artifactory. Nexus is not always tested all that well with older Maven versions :(