Configuring Apache Archiva with Tomcat 7

Apache Archiva is a repository manager that is capable of proxying other repositories. (By default it will proxy Maven Central). Archiva is useful for large builds such as Big Top as the ~4.1GB of Maven artifacts from all over the internet can be centralised in a more controlled place within Linaro. This means that if one of the many servers glitches; our CI builds still progress forwards.

There is a standalone version of Apache Archiva, but this requires a native Java Service Wrapper (JSW) http://sourceforge.net/projects/wrapper/ to launch.

One can also configure Apache Archiva to run inside Apache Tomcat. This page details how this can be accomplished on Debian Jessie with Apache Tomcat 7.

Pre-requisites

  • sudo apt-get install apache-tomcat7

  • wget http://mirror.ox.ac.uk/sites/rsync.apache.org/archiva/2.2.0/binaries/apache-archiva-2.2.0.war

  • wget http://mirror.ox.ac.uk/sites/rsync.apache.org/archiva/2.2.0/binaries/apache-archiva-2.2.0-bin.tar.gz

Deployment instructions

These were loosely based on the ones at: http://archiva.apache.org/docs/2.2.0/adminguide/webapp.html

  • Set up directory for Archiva to reside:

cd /var/lib/tomcat7
sudo mkdir archiva
sudo cp ~/apache-archiva-2.2.0.war archiva
sudo mkdir archiva/conf
sudo touch archiva/conf/archiva.xml
sudo chown -Rv tomcat7:tomcat7 archiva
  • Create /var/lib/tomcat7/conf/Catalina/localhost/archiva.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/archiva"
         docBase="${catalina.base}/archiva/apache-archiva-2.2.0.war">

<Resource name="jdbc/users" auth="Container" type="javax.sql.DataSource"
           username="sa"
           password=""
           driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
           url="jdbc:derby:/var/lib/tomcat7/archiva/user-database;create=true" />

<Resource name="mail/Session" auth="Container"
            type="javax.mail.Session"
            mail.smtp.host="localhost"/>

</Context>
  • Create /usr/share/tomcat7/bin/setenv.sh:

# I used the latest JDK from Linaro, this may not be needed
export JAVA_HOME="/var/lib/linaro-java/jdk8-server-release-1510"

# Let Archiva know where it is
export CATALINA_OPTS="-Dappserver.home=$CATALINA_BASE/archiva -Dappserver.base=$CATALINA_BASE/archiva"

# I needed to beef up the maximum heap size
export JAVA_OPTS="-Xmx4G"
  • Add pre-requisite libraries to Tomcat7, these come from the apache-archiva-2.2.0-bin.tar.gz.

    • tar xvf apache-archiva-2.2.0-bin.tar.gz

    • cd apache-archiva-2.2.0/lib

    • sudo cp derby-10.10.1.1.jar /usr/share/tomcat7/lib/

    • sudo cp activation-1.1.jar /usr/share/tomcat7/lib

    • sudo cp mail-1.4.jar /usr/share/tomcat7/lib

  • We are now ready to start tomcat7 with sudo service tomcat7 start

  • Wait until the CPU usage dies down for the java process.
  • A quick wget can test to see if everything is working:
    • wget http://<SERVERIP>:8080/archiva/repository/internal/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar

  • If the wget succeeds everything is good!

If things go wrong

There are a lot of moving parts with Tomcat and Archiva, and a slight typo/variation in initial conditions may necessitate some debugging. The following two files should be inspected if anything goes wrong:

  • /var/log/tomcat7/catalina.out

  • /var/lib/tomcat7/archiva/logs/archiva.log

Keep an eye out for OutOfMemoryErrors as these will require some raising of the parameters in setenv.sh.

Running inside a Docker container

I ran this in a Jessie Docker container on AArch64 and noticed that when I ran service tomcat7 start the startup scripts reported an error. Looking closer, Tomcat7 was actually started successfully though and Archiva ran fine.

The archiva web-ui

One can see things graphically by browsing to: http://SERVERIP:8080/archiva

Hooking up Apache Big Top Build to Archiva

Maven

One can redirect Maven via the file ~/.m2/settings.xml

<settings>

<mirrors>
    <mirror>
      <id>archiva.default</id>
      <url>http://<SERVERIP>:8080/archiva/repository/internal/</url>
      <mirrorOf>external:*</mirrorOf>
    </mirror>
</mirrors>

</settings>

Ivy

Ivy is tricky as the configuration is per project and I've not found any way to override this. There are some commits being worked on in the Linaro ODPI Big Top tree that automatically override the ivysettings.xml files with the one stored at ~/ivysettings.xml. A sample configuration can be found below:

<?xml version="1.0" encoding="UTF-8"?>
<ivysettings>
<settings defaultResolver="archiva" />
<property name="archiva-internal"
    value="http://<SERVERIP>:8080/archiva/repository/internal" />
<resolvers>
    <ibiblio name="archiva" m2compatible="true" root="${archiva-internal}" />
</resolvers>
</ivysettings>

Extra Archiva remote repositories needed for Apache Big Top

The following extra remote repositories needed to be connected to the internal repository (central was connected by default):

  • http://maven.ow2.org/maven2/

  • http://repo.maven.apache.org/maven2/

  • http://conjars.org/repo/

  • http://www.datanucleus.org/downloads/maven2/

  • http://repo1.maven.org/maven2/

  • https://repository.apache.org/content/groups/snapshots/

  • https://repository.cloudera.com/artifactory/ext-release-local/

  • https://repository.cloudera.com/artifactory/cloudera-repos/

  • http://maven.twttr.com/

  • http://repository.jboss.org/nexus/content/groups/public/

LEG/Engineering/BigData/configuring-archiva-with-tomcat7 (last modified 2016-03-21 23:04:39)