Claudio Claudio -4 years ago 130
Bash Question

jEdit Python Shell plugin fails to run Python3 (How to update a file in a .jar archive?)

What puzzles me is, how does it come that the Python Shell plug-in for jEdit does not work with Python3? The issue seem to be known since year 2012 and apparently no one has yet provided an updated version ( http://www.jedit.org/oldtrackers/Plugin%20Feature%20Requests/3498547.html ) of this plug-in working for both Python2.x and Python3.x .
Am I alone with the need of having this plug-in up an running in jEdit?

The problem is that this plug-in uses the execfile() function which is not available in Python3. In order to provide a fix it is necessary to replace in PythonShell.java code of this plugin:

execfile("filename")


with

exec( open("filename").read() )


For me who is not very familiar with Java it was very hard to get an updated PythonShell.jar out of the adjusted PyhonShell.java file.
What I still fail to understand after success with fixing the problem is how to use jar. After many various approaches I came finally out with:

jar -u PythonShell.jar -C python/shell PythonShell.class


but also this gave me the same as I was getting all the time:

jar: `-u' mode requires a file name


The jar's -help was not able to help me understand what I did wrong in all my attempts to replace the PythonShell.class file in the PythonShell.jar with the new version got from compiled PythonShell.java file.

My workaround was to rename the .jar to .zip, put the PythonShell.class file into it using a File Manager and then rename it back to .jar, but I would be glad to get rid of the bad gut feeling of not understanding how the 'jar' command works.

Answer Source

The jar command by default works in streamed mode. This means if you do jar -c foo, it takes the file foo creates a JAR out of it and outputs it to stdout. You can then either redirect this to a file (jar -c foo >foo.jar), or you can use -f to instruct jar to create a file (jar -cf foo.jar foo).

The same applies when updating a JAR file, you can either stream the input in and the output out like cat foo.jar | jar -u foo >foo2.jar or you can use -f to instruct it to update the file in place like jar -uf foo.jar foo.

If you tell it to update a file using -u, but you don't specify which file to update with -f and are not giving anything on stdin, then it cannot work as it does not know what file to update.

PS: You are welcome to submit a patch to https://sourceforge.net/p/jedit/plugin-patches for the plugin maintainer to accept, or overtake maintenance of the plugin if there is no active maintainer and you want to overtake.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download