mob-i-l
Posts: 315
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

[bug] Rhino JavaScript via Java

Wed Apr 02, 2014 7:18 pm

There is a bug in Rhino: when I stand at the end of a line and presses left arrow the cursor visually jumps to the 5th character from the end instead of the 1st. But it acts as if it just backed one character. This makes it very difficult to edit the command line. Rhino works well in Ubuntu 10.04 so this is probably a Raspbian-specific problem. I would like to have Rhino working since I intend to use it in a CoderDojo to teach JavaScript in combination Minecraft Pi Edition, see topic Extend Minecraft Pi Edition using JavaScript via Java.

In this example I start Rhino and press arrow-left, BackSpace and Enter:
$ rhino
Rhino 1.7 release 3 2012 02 13
js> 0987654321
98765431
js>

Rhino was installed by:
$ sudo apt-get install rhino

Rhino uses the built-in Java from Oracle, which I think is good since it saves space and time compared to downloading OpenJDK.

Rhino is a script that calls Java:
$ cat `which rhino`

Code: Select all

#!/bin/sh

JAVA_CMD="/usr/bin/java"
JAVA_OPTS=""
JAVA_CLASSPATH="/usr/share/java/js.jar:/usr/share/java/jline.jar"
JAVA_MAIN="org.mozilla.javascript.tools.shell.Main"

## 
## Remove bootclasspath overriding for OpenJDK since
## it now use a mangled version of Rhino (in sun.org.mozilla.rhino package)
##
## References:
## <https://bugs.launchpad.net/ubuntu/+source/openjdk-6/+bug/255149>
## <http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=179>
## <http://www.openoffice.org/issues/show_bug.cgi?id=91641>
##

$JAVA_CMD $JAVA_OPTS -classpath $JAVA_CLASSPATH $JAVA_MAIN "$@"
I posted this in this Java-group rather than in the Raspbian-group because I think people here can solve the problem since it might be due to incompatibility between Oracle Java and OpenJDK.
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: [bug] Rhino JavaScript via Java

Thu Apr 03, 2014 8:38 am

Note that rhino uses "jline" for the console line editing.
http://jline.sourceforge.net/

Thus if jline misbehave then first try use the latest version of jline to check if the issue you report is fixed by the jline developers.

It looks like the issue you report has possibly been fixed
https://github.com/jline/jline/commit/4 ... 57f30aae65

you may also try the next version of jline (2)
https://github.com/jline/jline2



You may also read the rhino enhancement bug where rhino got extended to use jline for command line editing.
Thus if jline causes trouble you can ommit the jline jars from the rhino classpath and you will get the old rhino behaviour without jline.
https://bugzilla.mozilla.org/show_bug.cgi?id=418034
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

mob-i-l
Posts: 315
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

Re: [bug] Rhino JavaScript via Java

Thu Apr 03, 2014 8:40 pm

I tried jline-1.0.jar (sourceforge), jline-1.1-SNAPSHOT.jar (github), jline-2.12-SNAPSHOT-sources.jar (github), and original-jline-2.12-SNAPSHOT.jar (github).
The newest jline1-versions had the same problem as before. The jline2-versions are probably not compatible with js.jar since the results with these are the same as not using jline at all i.e. you get VT100-escape codes when you press the arrow-keys: ^[OD^[OB^[OA^[OC .

I had to install maven2 in order to compile the github sources. I compiled (mvn package) using Java7 by setting JAVA_HOME. Maven2 also installed JRE from OpenJDK6. I therefore changed my command-line so I called Oracle's Java7:

Code: Select all

/usr/lib/jvm/jdk-7-oracle-armhf/bin/java -cp /usr/share/java/js.jar:/home/pi/Downloads/jline-master/target/jline-1.1-SNAPSHOT.jar org.mozilla.javascript.tools.shell.Main
I got the same wrong behavior when I used Java6 from OpenJDK6 JRE.

Note that arrow-keys work well in Rhino for Ubuntu 10.04 LTS with OpenJDK6. This seems to be a Raspberry Pi-specific problem.

Edit:
It was rather difficult to uninstall maven2 completely but I succeeded using:

Code: Select all

sudo apt-get purge maven2
sudo apt-get autoremove
sudo apt-get purge icedtea-6-jre-cacao icedtea-6-jre-jamvm
sudo apt-get purge openjdk-6-jre-headless openjdk-6-jre-lib
I found a workaround to get working readline-functionality in Rhino:
sudo apt-get install rlwrap
rlwrap java -cp /usr/share/java/js.jar org.mozilla.javascript.tools.shell.Main
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

mob-i-l
Posts: 315
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

Re: [bug] Rhino JavaScript via Java

Sat May 02, 2015 8:21 am

I discovered that the original rhino/js has Tab-complete/autocomplete, but when you use rlwrap this disappears, and there seems to be no way to get this to work except getting a working jline.jar:
http://stackoverflow.com/questions/9210 ... n-disabled .

/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/bin/jjs doesn't have Tab-complete according to http://www.selikoff.net/2015/01/25/usin ... rimenting/ .

Anyone got a version of jline that works in the cases above?
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

Return to “Java”