Skip to content

Instantly share code, notes, and snippets.

Last active May 12, 2022
What would you like to do?
ORDS Create Deploy WAR
# Python code to create a new ords.war that can be deployed to a supported Apache Tomcat or WebLogic Server container.
# The created web archive is based on the ords.war distribution but has the following modification:
# - The META-INF files are not copied.
# - The web.xml has the configutation directory explicitly set. Setting the config.url environment variable is not required.
# Usage: create_deploy_war <source ords.war> <destination war filename> <configuration directory>
import zipfile
import sys
import os
import xml.etree.ElementTree as ET
# Update the web.xml context-param for configuration directory
def setConfigDir(data, configdir):
newEntry = '<context-param><param-name>config.url</param-name><param-value>' + configdir + '</param-value></context-param></web-app>';
webXML = data.decode().replace('</web-app>', newEntry);
return webXML;
# Read the input war and write the output war. Do not write certain files and modify the web.xml.
def repackage(source, destination, configdir):
with zipfile.ZipFile(source, 'r') as zipread:
with zipfile.ZipFile(destination, 'w') as zipwrite:
for item in zipread.infolist():
# The META-INF files will be ignored
if not item.filename.startswith('META-INF/'):
data =;
# The web.xml should be modified
if item.filename == 'WEB-INF/web.xml':
data = setConfigDir(data, configdir);
zipwrite.writestr(item, data);
# Simple arguments validation
def validateArgs():
if len(sys.argv) != 4:
sys.exit('Syntax: create_deploy_war <source ords.war filename> <destination war filename> <configuration directory>');
if not zipfile.is_zipfile(sys.argv[1]):
sys.exit('Source ords.war is not valid');
if not os.path.isdir(sys.argv[3]):
sys.exit('Configuration directory does not exist');
# main
repackage(sys.argv[1], sys.argv[2], sys.argv[3]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment