Installing a jar file to your local maven repository (fast)

September 15, 2011

There’s mvn:install-file, yes.
But it happens pretty often that the jar file you want to install already has a pom.xml in it that contains the information required on the command line and can be reused so that all you really should need to specify is the jar file you want to install.
The way it is, things are particularly inconvenient if you need to get 150+ jar files into your local repository.

Although this should go into mvn:install, here’s a quick-fix. Just call it with the filename of the jar file to install. Um, and do this in a tmp space, this leaves clutter.

#!/bin/bash
 
filename=$1
 
if [ "x$filename" = "x" ]; then
	echo "please feed me a file"
	exit 1;
fi
 
POM=$(jar tf $filename | grep pom.xml)
if [ "$?" -ne "0" ]; then
	echo "no pom.xml in file $filename. cannot automatically install this"
	exit 2;
fi
 
POM=$(echo $POM | head -1)
echo "proceeding with POM $POM"
 
jar xf $filename $POM
 
mvn install:install-file -Dfile=$filename -DpomFile=$POM

And here’s the complete goodness for shuffling all artefacts from a running CQ instance into your local maven repository:

#!/bin/sh
 
[ -z "$CRX_URL" ] && CRX_URL=http://localhost:4502
[ -z "$CRX_CREDENTIALS" ] && CRX_CREDENTIALS=admin:admin
 
curl -H x-crxde-version:1.0 -H x-crxde-os:mac -H x-crxde-profile:default -u $CRX_CREDENTIALS $CRX_URL/bin/crxde.classpath.xml > .classpath
FILE_LIST=`cat .classpath | sed -n '/lib/s/.*WebContent\(.*\)\".*/\1/p'`
for file in $FILE_LIST; do
	echo "Downloading $file"
	curl -u $CRX_CREDENTIALS $CRX_URL$file -O
done
 
for filename in *.jar; do
	POM=$(jar tf $filename | grep pom.xml)
	if [ "$?" -ne "0" ]; then
		echo "no pom.xml in file $filename. cannot automatically install this"
	else
		POM=$(echo $POM | head -1)
		echo "proceeding with POM $POM"
 
		jar xf $filename $POM
 
		mvn install:install-file -Dfile=$filename -DpomFile="$POM"
	fi
done

Leave a Reply

Your email address will not be published. Required fields are marked *

*



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>