Skip to content

Instantly share code, notes, and snippets.

@rponte
Last active September 23, 2017 17:11
Show Gist options
  • Save rponte/6793599 to your computer and use it in GitHub Desktop.
Save rponte/6793599 to your computer and use it in GitHub Desktop.
Deploying a java app with shellscript through SSH - simple and efficient
#!/bin/bash
set -e # Exit script immediately on first error.
#set -x # Print commands and their arguments as they are executed.
# generate war file with ant or gradle or whatever you want
ant war
# upload the generated war file to the web server
scp -P 5122 target/war/MyApp-SNAPSHOT.war [email protected]:~/MyApp.war
# deploy the uploded war file in tomcat
ssh -p 5122 [email protected] 'bash -s' <<'ENDSSH'
pwd
tomcat_home/bin/shutdown.sh
sleep 5
rm -rf tomcat_home/webapps/MyApp
rm -rf tomcat_home/webapps/MyApp.war
cp MyApp.war tomcat_home/webapps
tomcat_home/bin/startup.sh
ENDSSH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment