From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id C87D17EF29 for ; Fri, 18 Dec 2015 23:54:04 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.20,447,1444687200"; d="scan'208";a="193052463" Received: from cse35-1-82-236-143-147.fbx.proxad.net (HELO alnitak.irisa.fr) ([82.236.143.147]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 18 Dec 2015 23:54:04 +0100 Message-ID: <56748EF8.5010009@irisa.fr> Date: Fri, 18 Dec 2015 23:55:52 +0100 From: Sebastien Ferre Organization: IRISA User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: caml-list@inria.fr References: <8D722630-1CB1-413B-9F90-1F975FA5B64B@gmail.com> <4D6A138A-AA9F-4DFB-85E8-38B44983EC11@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Validation-by: sebastien.ferre@irisa.fr Subject: Re: [Caml-list] Invoking Java programs from an OCaml program Hi, I have used camljava in one project. I found that solution satisfying although it does involve a lot of boilerplates, indeed. It makes it possible to use a JAR a bit like a C library. At runtime, it is sufficient to set the CLASSPATH. If you are curious, visit http://www.irisa.fr/LIS/softwares/pew/ from where you can find the source code, and execution instructions. (boilerplate code is in file owlapi.ml) I am interested by solutions to ease the generation of boilerplates. Best, Sébastien Ferré On 12/18/2015 11:25 AM, Seungcheol Jung wrote: > 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 > wrote: > > >> On Dec 15, 2015, at 6:21 AM, Paul Pelzl > > wrote: >> >> On Mon, Dec 14, 2015 at 9:25 AM, Chan Ngo > > 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. >> https://ocaml.github.io/ocamlunix/ocamlunix.html >> >> >> 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, > > --- > Chan Ngo > INRIA, > (+33)02 99 84 72 84 > chan.ngo@inria.fr > http://people.rennes.inria.fr/Chan.Ngo > >