The JAR file format is a container and compression file format. Each JAR file contains other compressed files. JAR files are very easy to open. The JAR format is identical to the ZIP file format which means that it is natively supported by Python (using zipfile package).
This URL is specified in the file “app-context.xml” which is in the path (inside this jar) “META-INF\spring”. The “defaultLocation” attribute contains this URL. See below the example of the XML content of the file.
The purpose of the Python script is to allow us to easily change this URL and create a JAR file for specific testing. For example if we are testing a new server version then we would want a JAR file pointing to that server. Currently we change it manually.
The input parameters to the script should be (see example below):
1) The original JAR file path
2) The desired URL to replace the content of the attribute "defaultLocation" in the app-context.xml file in the META-INF\spring folder in the JAR. Note: you can do a regular expression to replace it and not required to really fully parse the XML. Look for the REGEXP 'defaultLocation="([^"]*)"' and replace \1 with the URL from the command line.
3) The path to the output JAR file (if not specified , it will just overwrite the JAR file given in the first parameter).
The output is the JAR file with the input URL in it (as specified above).
The script should support two executing methods: from the command line and from another python code (imported function), so you have a main function called with the parameters from the command line arguments. The entire thing should be a few lines of code, if you go beyond 10-20 lines, check with me if you miss something or I underestimated it...
Exmaple for the XML content:
<?xml version="1.0" encoding="UTF-8"?>
<content moduleId="com.tc" category="MISCELLANEOUS" messageBaseName="META-INF/resources/message"
width="800" height="360" resizable="false" />
Example of the activation:
update_jar e:\test\jar1.jar 2-1-0-53-dot-traders-compass.appspot.com e:\test\jar2.jar