请耐心等待,因为这是我使用 Tomcat 的第一个 Java servlet。我是在 Windows 上的 Eclipse 中编写的,需要为其编写构建脚本和运行脚本。
据我所知,我将其发送给的用户需要安装 Tomcat 才能运行此 WAR。
如果是这样,我的构建脚本将需要 1.在自己的笔记本电脑上安装tomcat 2. 向它部署我的 war
我的运行脚本只需要运行我的程序?
最佳答案
我认为这可以帮助你: <强> 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
这是一个 sh 文件,因此您可以在 Linux 中使用。
关于java - 编写 shell 脚本来构建和部署 WAR 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36437395/