Following up on Brian's suggestion of using JLine, this worked reasonably well.
I finally could use up/down to browse through command-history, but it had some shortcomings, such as no support for ALT+DEL (to delete last word), CTRL+LEFT/RIGHT (to move cursor one word back/forward) and CTRL+R (reverse search past commands).
I then learnt that such facilities are being offered by JLine2, so I put some time into trying that out instead.
It was quite a painful journey, as I'm on OpenSUSE 12.3 presently, I won't bore you with all the details, but I will outline them, in-case you're really keen on this and find yourself having to follow a similar journey:
- JLine2 is only offered with source (atleast on OS12.3), so no easy rpm install
- It requires maven to build it (which the official OpenSUSE 12.3 repositories don't offer, but thankfully there is an un-official rpm someone made for it)
- Since I'm building it from work, Maven had proxy issues, so I needed to provide my proxy details in the "/usr/share/maven2/conf/settings.xml" file.
- Then when I typed "mvn install", there were problems with a few maven project dependencies that I had to download+install manually ("maven-scm-api-1.5.jar", "jansi-1.11.jar" and "bsh-2.0b4.jar")
- After this, it finally built, but had problems running, but I solved these via a tweak mentioned here
After this, it worked reasonably ok, I get most of the perks I was missing out on with JLine1, but unfortunately, jdb's "> " prompt seems to interfere with the movement of the cursor during the CTRL+LEFT/RIGHT actions, which is a shame.
For now, I get around this by typing CTRL+P followed by CTRL+N (this seems to clear the "> " prompt and make everything work nicely)
SIDE-NOTE: I found it painful to type a big long command to run jdb with jline, so I found it nicer to run jline2+jdb via a bash-script such as this:
#!/bin/sh
#GI: This is a version of jdb that runs via jline, so that you can up/down through command history
# JLINE V1.0 METHOD
# =================
#/usr/local/jdk1.6.0_29/bin/java -classpath /usr/share/java/jline.jar:/usr/local/jdk1.6.0_29/lib/tools.jar jline.ConsoleRunner com.sun.tools.example.debug.tty.TTY $*
# JLINE V2.* METHOD
# =================
/usr/local/jdk1.6.0_29/bin/java -classpath /usr/share/java/jline.jar:/usr/local/jdk1.6.0_29/lib/tools.jar jline.console.internal.ConsoleRunner com.sun.tools.example.debug.tty.TTY $*
For example, you could then run your program via jline+jdb with a much simpler:
jjdb.sh -classpath './*':'../lib/*' myprogram.MyMainClass
Ok, hope that helps anyone that's craving a bit more. If you need more detail on any of my journey, let me know, I keep fairly detailed logs, but just didn't want to burden the reader with too much detail (unless it turns out you really needed it!:))