Hi, list.

I am also looking for a way to use Java library in OCaml application. My OCaml
application is performance-critical static source code analyzer. I found two
options: X. Clerc's OCaml-Java and X. Leroy's camljava. Which one is more
suitable?

1. OCaml-Java
From my understanding, OCaml-Java[1] compiles OCaml code into byte code and
packs the byte code, interpreter, and Java code into one Java application. It
looks more like embedding OCaml code in Java, not getting some help from
Java. So it does not satisfy my pro-OCaml taste. I am also concerned about
slowdowns due to byte code and interpreter.

2. camljava
I think camljava[2] is more suitable for my purpose. Using camljava, I can
launch JVM and call Java methods via JNI from native OCaml applications.
However, it is a very low-level interface so that I need to implement many
boilerplates by hand (O'Jacaré[3] might reduce some burden?) and beware of
type-safety. Also, it is not maintained for a long time (the latest
version came out before ten years ago).

Do you have any suggestions? Moreover, could anyone share some real-world
stories about OCaml-Java binding?


Regards,
Seungcheol Jung

[1] http://www.ocamljava.org/
[2] https://forge.ocamlcore.org/projects/camljava/
[3] http://www.pps.univ-paris-diderot.fr/~henry/ojacare/index.en.html


On 16 December 2015 at 22:29, Chan Ngo <chan.ngo2203@gmail.com> wrote:

On Dec 15, 2015, at 6:21 AM, Paul Pelzl <pelzlpj@gmail.com> wrote:

On Mon, Dec 14, 2015 at 9:25 AM, Chan Ngo <chan.ngo2203@gmail.com> wrote:
An alternative, if you want to do as follows:
- Compile Java program to an executable (not jar file)
- Call this executable and get the return values from it

So you can think about Unix module in OCaml, you can use the standard I/O to realize a communication channel between your OCaml code and the executable Java.


If the data to be exchanged is structurally complex, then this technique becomes difficult; a cross-platform serialization library can be very helpful for generating appropriate serialization code in multiple languages.  As one example, Cap'n Proto has bindings for both Java and OCaml: https://capnproto.org/otherlang.html

Yes, I agree, in some cases, it will become difficult and we need a cross-platform serialization library. Your example is a good point. In addition, if you can control the source code of the Java side, you can modify the code such that it can return the result as JSON object then the OCaml side can get this object value to parse complex data structures.

Best,