Wednesday, February 4, 2009

How to invoke maven to perform a jar library install

Invoke this installjar with:
sudo -u maven /home/maven/installjar $1 $2 $3 $4
Don't forget to add your user to the sudoers file.


> cat installjar
#!/bin/sh

# ==========================================
# by Alan Lupsha, 02/04/2009
# Installs a jar into the Maven2 repository
# ==========================================

GROUP=$1
ARTIFACT=$2
VERSION=$3
JARPATH=$4

MAVEN_DIR=/home/maven
export JAVA_HOME=/opt/SDK/jdk

checkUserArgs()
{
if [ "$GROUP" = "" ] ; then
syntax
fi
if [ "$ARTIFACT" = "" ] ; then
syntax
fi
if [ "$VERSION" = "" ] ; then
syntax
fi
if [ "$JARPATH" = "" ] ; then
syntax
fi

if [ -s "$JARPATH" ] ; then
echo "[ALAN] OK: file exists: $JARPATH"
else
echo "[ALAN] Error: file does not exist: $JARPATH"
echo "[ALAN] Make sure to upload the file there first, before executing the script"
RETURN_CODE=1
exit $RETURN_CODE
fi
}

syntax()
{
echo "[ALAN] ERROR: Please use the following syntax: ./installjar group artifact version path"
echo "[ALAN] "
echo "[ALAN] EXAMPLE: "
echo "[ALAN] To install jar file called servlet1.3.jar from your local directory, by placing it "
echo "[ALAN] in group basej2ee with the name servlet and version 1.3, do the following: "
echo "[ALAN] 1. FTP your jar into your directory, example: /home/smith_j/servlet1.3.jar"
echo "[ALAN] 2. Execute: ./installjar basej2ee servlet 1.3 ~/servlet1.3.jar "
echo "[ALAN] "
echo "[ALAN] 3. In your project's pom.xml file add the following dependency: "
echo "[ALAN] <dependency>"
echo "[ALAN] <groupId>basej2ee</groupId>"
echo "[ALAN] <artifactId>servlet</artifactId>"
echo "[ALAN] <version>1.3</version>"
echo "[ALAN] </dependency>"
echo "[ALAN] "
echo "[ALAN] Good luck."
RETURN_CODE=1
exit $RETURN_CODE
}

installFile()
{
/bin/mkdir $MAVEN_DIR/projects/
cd $MAVEN_DIR/projects/

COMMAND="/maven/maven-2.0.6/bin/mvn install:install-file -DgroupId=$GROUP -DartifactId=$ARTIFACT -Dversion=$VERSION -Dpackaging=jar -Dfile=$JARPATH"
echo "[ALAN] Executing command: "
echo "[ALAN] $COMMAND"

/maven/maven-2.0.6/bin/mvn install:install-file -DgroupId=$GROUP -DartifactId=$ARTIFACT -Dversion=$VERSION -Dpackaging=jar -Dfile=$JARPATH

echo "[ALAN] "
echo "[ALAN] Don't forget to add the following dependency in your project's pom.xml file:"
echo " <dependency>"
echo " <groupId>$GROUP</groupId>"
echo " <artifactId>$ARTIFACT</artifactId>"
echo " <version>$VERSION</version>"
echo " </dependency>"
echo "[ALAN] "
echo "[ALAN] If the install was successful, then you can remove your jar file from: $JARPATH "
}


checkUserArgs
installFile
echo "[ALAN] Finished! (questions, comments, concerns - email "

No comments:

Post a Comment