Nowadays, you can find almost any dependency on Maven. The keyword is almost any dependency. There are situations where some vendors do not upload their libraries on Maven. If you must use a JAR file that is not hosted on a Maven repository, you have two options:
- Add the JAR to your project and reference it from the file system. I would say this is not a very elegant solution, especially if you have many people working on the project.
- Upload the JAR to an internal Maven repository using FTP and use it like it was published on Maven. We will focus on this approach because it has more advantages in the long run.
Step by step guide
I will assume that you have an internal Maven repository and that you can upload artefacts there using FTP. If this is not the case, you can check out this tutorial which illustrates how to create an internal Maven repository. For this demonstration, we will also assume that the JAR file that you want to publish is named “custom-library.jar”
1. Make sure you have an FTP with corresponding credentials
2. Make sure that the connection details are specified in the Maven configuration file. The file is called “settings.xml” and it is located in the Maven installation directory, in a folder labelled “conf”.
... <server> <id>company-repository</id> <username>username</username> <password>password</password> </server> ...
3. Create an empty Maven Project
... <build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ftp</artifactId> <version>2.10</version> </extension> </extensions> </build> ...
6. Everything is in place 🙂 All you have to do now is to execute the following Maven goal:
mvn deploy:deploy-file -DrepositoryId=company-repository -Dfile=custom-library.jar -DgroupId=rc -DartifactId=custom-library -Dversion=1.0.0 -Dpackaging=jar -Durl=ftp://ip:port
- DrepositoryId is the id of the internal Maven repository that you use. This name is defined in the Maven configuration file.
- Dfile is the path to the JAR file that you want to upload to Maven
- DgroupId the group id that you want to associate with the JAR
- DartifactId the artefact id that you want to associate to the JAR
- Dversion the version that you want to associate with the JAR
- Durl is the FTP address where the JAR shall be uploaded. The username and password are specified in the Maven configuration file
Be aware that if you want to upload a custom JAR to Maven, you need to give it an artefact name, a group name and a version.