In CPython and JPython, the first index of sys.argv points to the name of the Python script, while the rest of the array elements refer to the arguments. However, in Websphere’s Jython, the first index already points to the first argument of the script. This means that none of the elements of sys.argv has the information about the name of the script it is running.
I think this is a serious drawback. I have some functionalities where I need access to the name of the script. For example, I need to know the directory where that script is located. This will allow me to navigate relatively to other files where the script is located like additional path to libraries (pythonpath ) or configuration files and be able to access them at runtime.
I have yet to figure out a trivial way to access the script name at runtime in wsadmin. One workaround I am planning is to write a wrapper script to grab the script name and then pass that information to wsadmin’s Jython script as the first parameter, so that would become sys.argv. Or perhaps as an option parameter with the value telling it that is the script name.
However, the problem with a wrapper script is that your wsadmin Jython scripts won’t be portable since it would be dependent on the wrapper to run.
If anyone out there has ideas other than a wrapper script, I’d love to hear it.