Another way to implement this without replacing the entire Tomcat server.xml file is using the following in your .ebextensions folder (e.g. tomcat.config)
files:
"/tmp/update_tomcat_server_xml.sh":
owner: root
group: root
mode: "000755"
content: |
#! /bin/bash
CONFIGURED=`grep -c '<Connector port="8080" URIEncoding="UTF-8"' /etc/tomcat7/server.xml`
if [ $CONFIGURED = 0 ]
then
sed -i 's/Connector port="8080"/Connector port="8080" URIEncoding="UTF-8"/' /etc/tomcat7/server.xml
logger -t tomcat_conf "/etc/tomcat7/server.xml updated successfully"
exit 0
else
logger -t tomcat_conf "/etc/tomcat7/server.xml already updated"
exit 0
fi
container_commands:
00_update_tomcat_server_xml:
command: sh /tmp/update_tomcat_server_xml.sh
This config creates a script (files) and then runs it (container_command). The script checks the server.xml for the UIREncoding="UTF8" string and if it doesn't find it, it then adds it in using the sed command.
The nice thing about this solution is that if you upgrade your version of Tomcat (e.g. from 7 to 8) then you don't have to worry about updating the server.xml in your various WAR files.
Also, this example is for adding the UIREncoding parameter but the script is very easily adapted to add <Connector ... />' property from the original question.