Maven repository in three steps

So you've crafted something that you'd really like to share with the masses. This post will demonstrate how to create your own Maven2 repository and put your piece of work there. The prerequisite is a domain name that you own (dom-ain.org) with a functional HTTP server up and running. Let's assume that you've developed a JAR library with groupId org.dom-ain and artifcatId xxxLib, excerpt from pom.xml:


<groupId>org.dom-ain</groupId>
<artifactId>xxxLib</artifactId>
<packaging>jar</packaging>
<name>xxxLib</name>
<version>0.0.4</version>

Step 1:


mvn install -DperformRelease=true -DcreateChecksum=true

This will create all necessary folder structures in your local Maven2 repository (which is located ~/.m2/repository on *nix, and somewhere else on other OSes), and will install all artifacts there (along with md5 and sha1 checksums).

Step 2:

Create a new folder 'maven2' in the HTTP server root so that it would be accessible by URL http://dom-ain.org/maven2. On HTTP server you MUST enable file listing for maven2 directory and all subfolders (which means 'Options Indexes' for Apache). Then copy the folder branch with the installed library from your local repository there. HTTP server folder structure would look like


[root@httpserv dom-ain.com]# ls -R maven2/
maven2/:
org

maven2/org:
dom-ain

maven2/org/dom-ain:
xxxLib

maven2/org/dom-ain/xxxLib:
0.0.4  maven-metadata-local.xml

maven2/org/dom-ain/xxxLib/0.0.4:
xxxLib-0.0.4.jar               xxxLib-0.0.4.pom
xxxLib-0.0.4.jar.md5           xxxLib-0.0.4.pom.md5
xxxLib-0.0.4.jar.sha1          xxxLib-0.0.4.pom.sha1
xxxLib-0.0.4-javadoc.jar       xxxLib-0.0.4-sources.jar
xxxLib-0.0.4-javadoc.jar.md5   xxxLib-0.0.4-sources.jar.md5
xxxLib-0.0.4-javadoc.jar.sha1  xxxLib-0.0.4-sources.jar.sha1

Step 3:

Rename maven2/org/dom-ain/xxxLib/maven-metadata-local.xml to maven-metadata.xml and create checksums for it:


cd maven2/org/dom-ain/xxxLib
mv maven-metadata-local.xml maven-metadata.xml
md5sum maven-metadata.xml > maven-metadata.xml.md5
sha1sum maven-metadata.xml > maven-metadata.xml.sha1

Now everything should work, just make sure that the repository is accessible from the browser. Try to go to this URL: http://dom-ain.org/maven2/org/dom-ain/xxxLib/0.0.4 -- the browser is supposed to list all JARs (you library JAR, sources and javadoc) along with their checksums. That's it, now you have your own Maven2 repository that can be referenced from other Maven2 projects. The reference to your repo in pom.xml will look like:


	<repositories>
		<repository>
			<releases>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
				<checksumPolicy>fail</checksumPolicy>
			</releases>
			<id>YourId</id>
			<name>YourName</name>
			<url>http://dom-ain.org/maven2</url>
			<layout>default</layout>
		</repository>
	</repositories>

The dependency (a reference) to your library will look like:


<dependency>
	<groupId>org.dom-ain</groupId>
	<artifactId>xxxLib</artifactId>
	<version>0.0.4</version>
</dependency>

Enjoy