This guide explains how to use the server as a repository for the Apache Maven build tool.
More precisely, I will show how to setup a private remote internal maven repository using the free Artifactory implementation.

Step 1 - Prepare environment

Relevant config files:

  • /home/artifactory/artifactory_base/etc/artifactory.system.properties (datasource name, if using mysql)
  • /home/artifactory/artifactory_base/etc/repo/filesystem-mysql/repo.xml (datasource, if using mysql)
  • /home/artifactory/tomcat/conf/server.xml
  • /etc/apache2/workers.properties (MountJk worker definition)
  • /etc/apache2/sites-available/default (MountJk entry)

A separate artifactory-user will be created, who will control the server.
The server software is installed in his home directory. This encapsulation provides more flexibility and a higher level of security.
The artifactory web application will be deployed into a tomcat servlet container.
How to setup a tomcat installation is described in this article: PostgreSQL and JBoss AS

Create artifactory user

Set up a new user called artifactory:

root@jiffybox # useradd -d /home/artifactory -m artifactory
root@jiffybox # usermod -a -G artifactory artifactory
root@jiffybox # chsh artifactory -s /bin/zsh

Setup a web container for the artifactory.war

Create a tomcat instance as described in PostgreSQL and JBoss AS, using the artifactory user and his home directory.
Tomcat will is now installed here: /home/artifactory/tomcat
Make sure your tomcat instance is configured to use unique ports.

Access the app on the default web port

If you want to access Artifactory on Port 80, mount it via JkMount to the apache HTTP server.

  1. Define/Enable the Connector in your <ARTIFACTORY_TOMCAT>/conf/server.xml
    <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" address="localhost"/>
  2. Add a worker that is used for the artifactory tomcat in: /etc/apache2/workers.properties
    worker.list=<EXISTING-WORKER-IDS>,artifactorytomcat
    # ... <EXISTING-WORKERS> ...
    worker.artifactorytomcat.type=ajp13
    worker.artifactorytomcat.host=localhost
    worker.artifactorytomcat.port=8010
  3. Mount the worker to "/artifactory* in: /etc/apache2/sites-available/default
    <VirtualHost *:80>
      ServerName bytesare.us
      [...]
      # artifactory tomcat instance: (maven repo)
      JkMount /artifactory* artifactorytomcat
    </VirtualHost>
                

Step 2 - Install and configure Artifactory

Relevant config files:

  • /home/artifactory/bin/tomcat_base/bin/setenv.sh

Unzip and deploy the software

Download and unzip the artifactory software in the home directory:

artifactory@jiffybox $ wget "http://sourceforge.net/projects/artifactory/files/artifactory/2.5.1.1/artifactory-2.5.1.1.zip/download" -O artifactory-2.5.1.1.zip
artifactory@jiffybox $ unzip artifactory-2.5.1.1.zip
The contents of the archive were unpacked in the directory artifactory-2.5.1.1. This is the directory that needs to be configure as "artifactory.home".
Let's create a link to highlight this fact:
artifactory@jiffybox $ ln -s artifactory-2.5.1.1 artifactory_base

Then link the war file contained in the artifactory_base to tomcat's webapps dir to deploy the war file. Set the "artifactory.home" Java variable in /home/artifactory/bin/tomcat_base/bin/setenv.sh to configure the base dir.

export JAVA_OPTS="$JAVA_OPTS -Dartifactory.home=/home/artifactory/artifactory_base"'

Configure Artifactory to use MySql Database (Optional)

By default, Artifactory uses the Apache-Derby in-memory database for the backend. Since we have MySql installed, we can save some memory (just a few megs) by using that database for artifactory.

In this example, a separate database user will be created for the backend.
(If you prefer, you can do this with the PhpMyAdmin tool.)

root@jiffybox # mysql -u root -p
CREATE DATABASE artifactory CHARACTER SET utf8;
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER,INDEX on artifactory.* TO 'artifactory'@'localhost' IDENTIFIED BY 'password1';

The next step installs the JDBC driver to the servlet container:

artifactory@jiffybox $ cd /tmp/
artifactory@jiffybox $ wget "http://www.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.19.zip/from/http://gd.tuwien.ac.at/db/mysql/" -O mysql-connector-java-5.1.19.zip
artifactory@jiffybox $ unzip mysql-connector-java-5.1.19.zip
artifactory@jiffybox $ cp /tmp/mysql-connector-java-5.1.19/mysql-connector-java-5.1.19-bin.jar /home/artifactory/tomcat/lib/

Then, create the datasource definition in the servlet container by adding this section to /home/artifactory/artifactory_base/etc/repo/filesystem-mysql/repo.xml:

<!-- MySQL Datasource -->
<DataSources>
    <DataSource name="ds">
        <param name="driver" value="com.mysql.jdbc.Driver"/>
        <param name="url" value="jdbc:mysql://localhost:3306/artifactory?useUnicode=true&characterEncoding=UTF-8"/>
        <param name="user" value="artifactory"/>
        <param name="password" value="password1"/>
        <param name="databaseType" value="mysql"/>
        <!-- Unlimited when not specified -->
        <!--<param name="maxPoolSize" value="80"/>-->
    </DataSource>
</DataSources>
    

Finally, configure the artifactory instance to use this database. Register the datasource name in the artifactory configuration.
Edit /home/artifactory/artifactory_base/etc/artifactory.system.properties and add/set this variable:

artifactory.jcr.configDir=repo/filesystem-mysql

Start and test Artifactory

by starting the servlet container with the formerly created tomcat-script:

artifactory@jiffybox $ /etc/init.d/tomcat-artifactory.sh start
Then, browse to the web console, login as 'admin' with 'password' (and change the password).

Step 3 - Configure the Maven client

Relevant config files:

  • ~/.m2/settings.xml
  • pom.xml's

Basic Configuration (Readonly Access)

Maven client configuration is quite simple. Browse to the artifactory console, and navigate to Client Settings / Maven Settings.
Then click on Generate Settings, and paste the content into your ~/.m2/settings.xml.
You shoud now be able to run maven builds that use your repo!

Configuration for a deployer

First, perform the basic configuration step. :-)
Login to the artifactory console as admin, and create a user.
In this example "andre" is created as someone that is allowed to deploy artifacts to the repository. (Read+Annotate+Deploy)

Next, login with the deployer-user. Click on the link that is labelled with the users name, and enter the password.
Copy the config snippet to your ~/.m2/settings.xml.
We will also set an ID to the server, so the pom's can later refer to this configuration.
It should look like this:

<settings>
  <servers>
      <server>
          <id>bytesare.us</id> <!-- referenced by the poms -->
          <username>andre</username>
          <password>\{DESede\}YOUR_CIPHER_PASSWORD==</password>
      </server>
  </servers>
  ...
<settings>
    
Then, we add this section to the pom.xml we want to deploy.
(I defined it in my super-pom)
<distributionManagement>
    <repository>
        <id>bytesare.us</id><!-- use credentials in settings.xml -->
        <url>http://bytesare.us/artifactory/libs-release-local</url>
    </repository>
    <snapshotRepository>
        <id>bytesare.us</id><!-- use credentials in settings.xml -->
        <url>http://bytesare.us/artifactory/libs-snapshot-local</url>
    </snapshotRepository>
</distributionManagement>
    

This way, every developer can use the same pom.xml files, and needs to configure just his own settings.xml.

Done, now try to deploy something with a simple

mvn deploy:deploy