Create a local self-hosted Maven Repository using JFrog

Anupam Roy
3 min readMar 1, 2022

Recently, I had to build an internal Maven Repository for the company I’m working in. Basically, there were libraries we had built which could not be uploaded to the public Maven Central because of security and privacy issues. These libraries were used within the test automation framework to perform certain jobs such as generating test reports, creating log files, taking test data from excel files etc. We needed to have a repository manager in place to deploy and download these Jar files from. This would eventually replace the manual work of adding libraries in every project.

Maven provides an official list of open source and commercial repository managers which can be used. Below is the list:

Available Repository Managers

The following list (alphabetical order) of open source and commercial repository managers are known to support the repository format used by Maven. Please refer to the respective linked web sites for further information about repository management in general and the features provided by these products.

After doing some initial research, I decided to go ahead with JFrog as the repository manager for internal Maven repository. I decided to go ahead with JFrog because of below reasons:

  1. Open source tool
  2. Good online community for debugging any issues
  3. Exhaustive features in the admin tool
  4. Easy setup and maintenance

Use below steps to have the JFrog Maven Repository up and running in no time!

Create a JFrog Home directory and move the downloaded installer archive into that directory, for example:

mkdir jfrogmove jfrog-artifactory-<pro|oss|cpp-ce>-<version>-windows.zip jfrogcd jfrog

Set the JFrog Home environment variable

set JFROG_HOME=<full path of the jfrog directory>

Extract the contents of the compressed archive and go to the extracted folder. Define the path to this folder as an environment variable called JFROG_HOME.

# Extract jfrog-artifactory-<pro|oss|cpp-ce>-<version>-windows.zip into jfrog foldermove artifactory-<pro|oss|cpp-ce>-<version> artifactory

Install Artifactory manually or as a service.
Manual Installation
Browse to %JFROG_HOME%\artifactory\app\bin and execute the file artifactory.bat.

Customize the product configuration (optional) including database, Java Opts, and filestore. Manage Artifactory using the following commands, in a Command Prompt window.

sc start|stop|query artifactory

Check Artifactory Log in the %JFROG_HOME%\artifactory\var\log\artifactory-service.log file.

Once the setup is done, you will need to manually Override the Built-in Repositories. To override the built-in central and snapshot repositories of Maven, you need to ensure that Artifactory is correctly configured so that no request is ever sent directly to them. To do so, you need to insert the following into your parent POM or settings.xml (under an active profile):

<repositories><repository><id>central</id><url>http://[host]:[port]/artifactory/libs-release</url><snapshots><enabled>false</enabled></snapshots></repository><repository><id>snapshots</id><url>http://[host]:[port]/artifactory/libs-snapshot</url><releases><enabled>false</enabled></releases></repository></repositories><pluginRepositories><pluginRepository><id>central</id><url>http://[host]:[port]/artifactory/plugins-release</url><snapshots><enabled>false</enabled></snapshots></pluginRepository><pluginRepository><id>snapshots</id><url>http://[host]:[port]/artifactory/plugins-snapshot</url><releases><enabled>false</enabled></releases></pluginRepository></pluginRepositories>

Once the setup is done is successfully, build a project to test the JFrog installation. If the project is built successfully using JFrog as a central repository, then the installation is done correctly. The only thing pending then would be to deploy a Jar file to the local repository. Use below command to deploy a Jar file to the locally running Maven repository.

Deploy to Jfrog Artifactory using:

mvn deploy

Conclusion

JFrog can be used as a Maven Repository Manager for building locally running repository. For certain projects (especially in corporate environments) the need to run an internal repository comes up quite often. Once you have installed and run the JFrog repository manager, you can play around with the admin portal for many other features as and when required.

Further reading: https://www.jfrog.com/confluence/display/JFROG/Administration

https://mvnrepository.com/artifact/com.jfrog.artifactory

https://www.theserverside.com/video/How-to-set-up-and-use-a-JFrog-Artifactory-Maven-repository

--

--

Anupam Roy

Quality advocate based in Sydney. I ❤️ to build scalable test automation frameworks. Always interested in investigating new tools and testing ideas.