Home > Computing > Henplus with Java-Readline for OS X

Henplus with Java-Readline for OS X

UPDATE: The procedure below is not entirely correct. It will work, but its not the most straight forward, and it probably won’t get you what you are really looking for. I have written a new procedure for building Java-Readline and GNU readline for OS X. Please use these instructions instead.


So, I found it time to revisit an old friend, HenPlus since I’ve been mucking around in a few databases lately.

The wrinkle this time, OS X. The main problem being the JNI interface to the GNU Readline library Java-Readline does not compile all that well on OS X.

Doing a bit of searching I found a few articles describing the steps to compile it, but they are slightly out of date for OS X 10.7 Lion, so I figured I’d put in my two cents.

For starters, Nathan Toone’s article Java-Readline on Mac OS X Update gets pretty close, but things have changed since he wrote it in 2006. So here’s my redux based on it.

Note that in my case, I did not care about building a universal binary (if that’s even possible on Lion) so I didn’t have to make as many changes as he did.

Tweaking Java-Readline


In the source root, edit Makefile and make the following changes:

  • Below the line # Operating system dependent
    Add JAVA_HOME = `/usr/libexec/java_home`
  • Clear out the JAVANATINC variable
  • Change the JAVAINCLUDE variable
    to /System/Library/Frameworks/JavaVM.framework/Headers
    (This is needed to find jni.h)

Next, edit src/native/Makefileand change the following:

  • Clear out the LIBPATH variable
  • Change the CFLAGS to -fno-common -DMAC_OS
  • Change $(CC) -shared (OBJECTS) $(LIBPATH) $($(TG)_LIBS) -o $@ to
    $(CC) -bundle -flat_namespace $(OBJECTS) $(LIBPATH) $($(TG)_LIBS) -o $@
  • Change the JavaReadline_LIBS variable to be -lreadline -ltermcap

Now, you need to edit src/native/org_gnu_readline_Readline.cand make the following changes:

  • On lines 98, 114, 213, and 224,
    change #ifdef JavaReadline to #if defined JavaReadline && !defined MAC_OS
  • On lines 216, 235, and 475,
    change #ifdef JavaEditline to #if defined JavaEditline || defined MAC_OS

Now, you can run make, and you will end up with libJavaReadline.so and libreadline-java.jar.

Rename libJavaReadline.so to libJavaReadline.jnilib.

I’ve made a patch script of all the changes to save anyone some effort in editing all the files by hand. Simply run

  • patch -p1 < libreadline-java-0.8.0-osx.patch

HenPlus Notes

Once you have compiled Java-Readline, you can compile HenPlus as described. A couple of things to note though

  • Copy libreadline-java.jar from Java-Readline into <INSTALLDIR>/share/henplus
  • Make <INSTALLDIR>/lib and copy libJavaReadline.jnilib into it
  • Change all occurrences of LD_LIBRARY_PATH in bin/henplus to DYLD_LIBRARY_PATH

And from there you should be set.

Categories: Computing
  1. January 13, 2012 at 7:11 am

    a very nice article, thanks for that!
    i did everything like described, the readline library seems to be found, i get this message during the henplus start:
    using GNU readline (Brian Fox, Chet Ramey), Java wrapper by Bernhard Bablok
    everything looks ok so far, no warning during the start
    but the readline featers just do not work, there is no auto completion on the TAB key, and there is no way using the history search with CTRL-R etc.
    i’m using Lion 10.7.2, java 1.6.0_29 on a MBP
    any tips?

    • February 6, 2012 at 8:45 am

      Tab completion works for me, at least for simple things. Tab on an empty line will show all the commands, for example, and if I enter sel it gets expanded to select.

      I do see that history search is not working for me either, its possible the patch I made disables portions of history completion, I’m not sure.

      • February 6, 2012 at 9:27 am

        A little closer inspection, trying to just run the libreadline-java test harness by hand does not provide history search either. I looked through my mods and it doesn’t look like any of them disable any portions of history management, which is confirmed by hitting arrow-up for example.

  2. February 6, 2012 at 4:20 pm

    Bingo! I’m not entirely sure what’s going on, but if you add the line

    bind “^R” em-inc-search-prev

    to ~/.editrc this seems to bring Ctr-R searching back to henplus.

    It sounds like what’s going on has to do with Apple providing libedit with OSX (instead of libreadline) but also linking libreadline to libedit in /usr/lib.

    I don’t know why that would effect henplus because it *should* be using the libreadline that was built, but perhaps it loads the library from /usr/lib instead?

    At any rate, this should help you.

    • André
      February 6, 2012 at 11:45 pm

      indeed, that entry helped to get the search back, even if it looks different, to the usual one
      now after the hit of CTRL-R i see “bck:” under the input line, insted of “(reverse-i-search)`’: ”
      but it works, which is the most important thing 🙂

      thanks for that! it helps a lot now!
      the tab completion is still unresolved 😉

    • February 7, 2012 at 9:08 am

      Ah. Duh, I’m stupid sometimes. So what we’re doing is building a dynamic library and JNI classes to use the “readline” library that’s in OSX (in /usr/lib/libreadline.dylib).

      However if you look at that file, its really a link to /usr/lib/libedit.3.dylib. From what I read, libedit has a compatibility layer so it can link to libreadline tools, the main reason why it was created, as I understand it, was as a non-GPL replacement.

      So I think what needs to be done is to first grab a copy of the real GNU readline, and build it first, then build libreadline-java against it, and finally it should all work as expected.

      • André
        February 8, 2012 at 2:23 am

        creechy :
        So I think what needs to be done is to first grab a copy of the real GNU readline, and build it first, then build libreadline-java against it, and finally it should all work as expected.

        Could you actually try that? 😉
        a howto like yours above would be very appreciated

  3. February 8, 2012 at 9:44 am

    I’ve rewritten the instructions to work with GNU readline. Take a look here https://creechy.wordpress.com/2012/02/08/compiling-java-readline-with-gnu-readline-for-osx/

  1. February 8, 2012 at 9:35 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: