Kevin
Kevin

Reputation: 3379

Writing shell script to build and deploy WAR file

Bear with me as this is my first java servlet using Tomcat. I wrote it in Eclipse on Windows, and need to write a build script and run script for it.

From what I'm told, the user who I send this to will need to have Tomcat installed in order to run this WAR.

If that's the case, my build script will need to 1. Install tomcat on their laptop 2. Deploy my war to it

and my run script just needs to run my program?

Upvotes: 0

Views: 8324

Answers (1)

Thiago Bomfim
Thiago Bomfim

Reputation: 428

I think this can help you : https://gist.github.com/geowa4/1428257

#!/bin/bash
TOMCAT=apache-tomcat-7.0.23
TOMCAT_WEBAPPS=$TOMCAT/webapps
TOMCAT_CONFIG=$TOMCAT/conf/server.xml
TOMCAT_START=$TOMCAT/bin/startup.sh
TOMCAT_ARCHIVE=$TOMCAT.tar.gz
TOMCAT_URL=http://apache.mirrorcatalogs.com/tomcat/tomcat-7/v7.0.23/bin/$TOMCAT_ARCHIVE
WAR_FILE=whatever.war

if [ ! -e $TOMCAT ]; then
if [ ! -r $TOMCAT_ARCHIVE ]; then
if [ -n "$(which curl)" ]; then
    curl -O $TOMCAT_URL
elif [ -n "$(which wget)" ]; then
    wget $TOMCAT_URL
fi
fi

if [ ! -r $TOMCAT_ARCHIVE ]; then
echo "Tomcat could not be downloaded." 1>&2
echo "Verify that eiter curl or wget is installed." 1>&2
echo "If they are, check your internet connection and try again." 1>&2
echo "You may also download $TOMCAT_ARCHIVE and place it in this folder."  1>&2
exit 1
fi

tar -zxf $TOMCAT_ARCHIVE
rm $TOMCAT_ARCHIVE
fi

if [ ! -w $TOMCAT -o ! -w $TOMCAT_WEBAPPS ]; then
echo "$TOMCAT and $TOMCAT_WEBAPPS must be writable." 1>&2
exit 1
fi

if [ ! -r $WAR_FILE ]; then
echo "$WAR_FILE is missing. Download it and run this again to deploy it." 1>&2
else
cp $WAR_FILE $TOMCAT_WEBAPPS
fi

This is a sh file, so you could use in Linux.

Upvotes: 1

Related Questions