Hosting a shared Maven repository on a remote server may be accomplished with a simple web server such as Apache HTTP server.
This works because most of the resolution and publishing logic of Maven is implemented in the client. That said, it works
only if you know the groupId
and artifactId
to be published, since appropriate directories must be created by hand.
Do consider using more sophisticated server software such as Artifactory or Sonatype Nexus. Below is the 'bare minimum' alternative.
Caution: this example exposes a writable directory without any authentication, and thus assumes a trusted network.
You'll need to load the following modules:
- WebDAV (mod_dav, mod_dav_fs, mod_dav_lock)
Define a virtual host for your repository. Create a configuration file named /etc/apache2/extra/httpd-maven2.conf
:
<VirtualHost *:8081>
DocumentRoot "/var/repository/root"
ErrorLog "/var/repository/log/error_log"
CustomLog "/var/repository/log/access_log" common
DavLockDB "/var/repository/lock/DavLock"
<Directory /var/repository/root>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
Dav On
<RequireAny>
Require method GET PUT DELETE POST OPTIONS
</RequireAny>
</Directory>
</VirtualHost>
Adjust the port number 8081
as appropriate.
Include the configuration file in /etc/apache2/httpd.conf
:
Include extra/httpd-maven2.conf
Create the repository directory with correct permissions. On MacOS the httpd user is _www
.
$ mkdir /var/repository
$ chown _www:_www /var/repository
$ mkdir -p /var/repository/root/maven2
Finally restart the server.
$ sudo apachectl restart
Configure your project to upload to your server. In pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>org.example</groupId>
<artifactId>myjar</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<distributionManagement>
<repository>
<id>myrepo</id>
<name>My Repository</name>
<url>http://127.0.0.1:8081/maven2</url>
</repository>
</distributionManagement>
...
You need to create the folder structure to support a given groupId
and artifactId
.
$ mkdir -p /var/repository/root/maven2/org/example/myjar/1.0
At last you should be able to publish to the server.
$ mvn deploy
I followed your guide, and it fails when trying to upload a new version of a package. Basically, fails when adding new files to the server. For it to work, I've had to add
dav:
in front of the repository url, asdav:http://127.0.0.1:8081/maven2
.As well, I have to add this extension to support the WebDAV protocol :