Notes on maven

Some useful (to me) things that I did not readily find in one place on the web.

Setting up a simple local maven repository

Without any server, so on the local host.
  1. Determine where to set up the repository, create a corresponding directory
    	mkdir /home/me/maven-repository
  2. Add the following to your pom.xml
    Then you can mention stuff as a dependency in pom.xml in the usual way:
To add e.g. a jar file /home/me/lib/stuff-1.0.0-alpha.jar containing a package to the local repository:
	mvn deploy:deploy-file -DartifactId=stuff \
        -Dversion=1.0.0-alpha -Dpackaging=jar \
        -Dfile=/home/me/lib/stuff-1.0.0-alpha.jar \
        -Durl=file:///home/me/maven-repository \
The following script automates this:
usage="$0 package path (e.g. $0 org.jaxen ~/download/jaxen-1.1.2.jar"
[ $# -eq 2 ] || { echo $usage; exit 1; }
file=$(basename $path)
id=$(echo $file| sed -e 's/-.*//')
version=$(echo $file| sed -e 's/[^-]*-//' | sed -e 's/.jar//')
echo "id=${id}, version=${version} .."
[ -f $path ] || { echo "Cannot open $path"; echo $usage; exit 1; }
mvn deploy:deploy-file \
  -DgroupId=${package} -DartifactId=${id} -Dversion=${version} \
  -Dpackaging=jar -Dfile=${path} -Durl=file://${repository} \

Replicating an artifactory repository

While artifactory has a nice web interface, the command line tool artadmin is more practical, e.g. to replicate repositories. Unfortunately, artadmin help export is rather confusing about the source/target of the export, and the same for import. Hopefully the following script, which replicates a local artifactory repository to a remote one, clarifies things a bit.
# This script assumes that both the local and remote artifactory
# servers run on port 8081 (the default) and use the same admin
# user name and password.
# artadmin lives in a directory which is usually not on ${PATH}
# artadmin creates exported archives in this directory
# the archive will be copied to ${destionation}:${tmpdir}
# 'artadmin help export' is a bit confusing:
#   export puts its result in a directory ${home}/${dir}/YYYYMMDD.hhmmss
#   where ${dir} is the artadmin argument and YYYYMMDD.hhmmss
#   corresponds to the current time 
# we use a new ${dir} to ensure that YYYYMMDD.hhmmss is the only child
# directory in ${dir}, thus $(ls ${home}/${dir}) will yield YYYYMMDD.hhmmss .
${artadmin} export ${dir} --username ${user} --password ${passwd} --m2
archive=$(ls ${home}/${dir})
# copy the archive directory to ${destination}:${tmpdir}/${archive}
tar -C ${home}/${dir} -z -cf - ${archive} | ssh ${destination} "cd ${tmpdir}; tar zxf -"
# artadmin help import needs the YYYYMMDD.hhmmss directory as argument
ssh ${destination} ${artadmin} import ${tmpdir}/${archive} \
  --username ${user} --password ${passwd}
rm -fr ${home}/${dir}
ssh ${destination} rm -fr ${tmpdir}/${archive}
The script can be downloaded from
Dirk Vermeir ( [Last modified: Mon Jun 1 17:46:22 CEST 2009 ]