Can anyone run Processing sketches in Jython?
in
Processing with Other Languages
•
3 months ago
It might take me a while to do the sensible thing and locate the appropriate Jython forum to post a question on, so since you guys are so nice and friendly and know all about Processing sketches, I thought I'd mention here that it currently doesn't appear to be possible to run Processing sketches on Jython. (unless I've mis-searched again, this issue doesn't appear to have been discussed here before).
To reproduce, open up a nice simple Java-mode sketch in the Processing IDE (mine is called “star”) and (from the 'file' menu) export it as an application. Then bring up a command prompt or shell and navigate to the “lib” directory that has just been created. I'm on Windows, on other platforms the file separator might be a colon rather than a semi-colon. Start by checking that the sketch runs normally:
D:\git\sketches\star\application.windows32\lib>java -cp star.jar;core.jar star
That much should work fine, but here's what happens if I try to run this sketch in Jython:
D:\git\sketches\star\application.windows32\lib>jython -Dpython.path=star.jar;cor e.jar
Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:48:36)
[Java HotSpot(TM) Client VM (Oracle Corporation)] on java1.7.0_25
Type "help", "copyright", "credits" or "license" for more information.
>>> import star
>>> star.main([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
at processing.core.PApplet.runSketch(PApplet.java:10407)
at processing.core.PApplet.main(PApplet.java:10205)
at star.main(star.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundE xception: star
And here are two further commands that I think are quite enlightening:
>>> x = star()
>>> x.getClass().getClassLoader()
org.python.core.SyspathJavaLoader@13aa36a
Jython has replaced the regular classloader (sun.misc.Launcher$AppClassLoader) with a class loader of it's own. The exception directs us to PApplet.java line 10407 and if we look at the line of code where the exception occurred
https://github.com/processing/processing/blob/12bb38f4b56a128b6e4eabe94836898aa1bb9e5b/core/src/processing/core/PApplet.java
We see that it is indeed trying to make use of the class loader. Unfortunately I think this is about as far as I'm going to get on my own, any advice would be welcome.
Best wishes,
Antony
To reproduce, open up a nice simple Java-mode sketch in the Processing IDE (mine is called “star”) and (from the 'file' menu) export it as an application. Then bring up a command prompt or shell and navigate to the “lib” directory that has just been created. I'm on Windows, on other platforms the file separator might be a colon rather than a semi-colon. Start by checking that the sketch runs normally:
D:\git\sketches\star\application.windows32\lib>java -cp star.jar;core.jar star
That much should work fine, but here's what happens if I try to run this sketch in Jython:
D:\git\sketches\star\application.windows32\lib>jython -Dpython.path=star.jar;cor e.jar
Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:48:36)
[Java HotSpot(TM) Client VM (Oracle Corporation)] on java1.7.0_25
Type "help", "copyright", "credits" or "license" for more information.
>>> import star
>>> star.main([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
at processing.core.PApplet.runSketch(PApplet.java:10407)
at processing.core.PApplet.main(PApplet.java:10205)
at star.main(star.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundE xception: star
And here are two further commands that I think are quite enlightening:
>>> x = star()
>>> x.getClass().getClassLoader()
org.python.core.SyspathJavaLoader@13aa36a
Jython has replaced the regular classloader (sun.misc.Launcher$AppClassLoader) with a class loader of it's own. The exception directs us to PApplet.java line 10407 and if we look at the line of code where the exception occurred
https://github.com/processing/processing/blob/12bb38f4b56a128b6e4eabe94836898aa1bb9e5b/core/src/processing/core/PApplet.java
We see that it is indeed trying to make use of the class loader. Unfortunately I think this is about as far as I'm going to get on my own, any advice would be welcome.
Best wishes,
Antony
1