Skip to content

Instantly share code, notes, and snippets.

@xpe
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpe/9857387 to your computer and use it in GitHub Desktop.
Save xpe/9857387 to your computer and use it in GitHub Desktop.
I use this script to build a WAR file (from a Clojure Pedestal app)
#!/usr/bin/env bash
set -e # exit on failure
[ -n "$DEBUG" ] && set -x # turn on command echo
# --------------
# Step 4: Deploy
# --------------
# Consult the documentation of your web container to find out how to deploy an
# application from a WAR file. For many web containers, it may be a simple
# matter of copying the .war file into a “webapps” directory.
HOST="myapp.my-domain.com"
scp etc/myapp.xml $HOST:myapp/
scp target/myapp.war $HOST:myapp/
ssh -qt $HOST \
'sudo cp ~/myapp/myapp.war /opt/myapp/; \
sudo chown -R jetty:root /opt/myapp/myapp.war; \
sudo cp ~/myapp/myapp.xml /opt/jetty/webapps/;
sudo chown -R jetty:root /opt/jetty/webapps/myapp.xml;\'
#!/usr/bin/env bash
set -e # exit on failure
[ -n "$DEBUG" ] && set -x # turn on command echo
# Adapted from "Building a WAR File" in the Pedestal Documentation
# http://pedestal.io/documentation/service-war-deployment/
# ---------------------------------
# Step Three: Build the WAR
# ---------------------------------
LOG="logs/make-war.log"
echo "Building target/myapp.war"
# Write date to log file
echo >> $LOG
date >> $LOG
# Copy correct dependencies
lein clean >> $LOG
lein pom >> $LOG
mvn dependency:copy-dependencies \
-DincludeScope=runtime \
-DexcludeScope=provided \
-DoutputDirectory=target/war/WEB-INF/lib >> $LOG
# Copy application files
mkdir -p target/war/WEB-INF/classes
cp -R src/* config/* resources/* target/war/WEB-INF/classes
rm -R target/war/WEB-INF/classes/public
# Copy public resources
cp -R resources/public/* target/war
# Copy web.xml
cp web.xml target/war/WEB-INF
# Create the WAR file
cd target/war && jar cvf ../myapp.war * >> ../../$LOG && cd ../..
echo 'Next, run `bin/deploy`
# Notes
#
# See
# * http://jira.codehaus.org/browse/MDEP-128
# * https://github.com/technomancy/leiningen/issues/1267
# * http://jira.codehaus.org/browse/MDEP-85
# * http://maven.apache.org/plugins/maven-dependency-plugin
#
# Maybe these will help?
# * http://stackoverflow.com/questions/9240862/access-to-resources-on-web-application-classpath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment