caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Invoking Java programs from an OCaml program
@ 2015-12-14 16:40 Soichi Sumi
  2015-12-14 17:25 ` Chan Ngo
  2015-12-15  9:06 ` forum
  0 siblings, 2 replies; 8+ messages in thread
From: Soichi Sumi @ 2015-12-14 16:40 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 854 bytes --]

I want to invoke Java programs and use their result
from an OCaml program in my research.

I have tried OCaml-Java to realize the integration
and succeeded to execute some example.However,
it cannot invoke objects defined by me, as far as
I read OCaml-Java document. I think it only realize
seamless integration of Java standard library and OCaml.

Is there anyway to use Java Object which defined by me
or to invoke jar file and use the result?

If you know another way to use the result produced by
Java programs, I want to know the way too.

Any help appreciated.

--Soichi Sumi
--OCaml-Java HP : www.ocamljava.org

=========================================
Soichi Sumi
Graduate School of Information Science and Technology
Osaka University
1-5, Yamadaoka, Suita, Osaka, Japan
Email: s-sumi@ist.osaka-u.ac.jp
=========================================

[-- Attachment #2: Type: text/html, Size: 1389 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Invoking Java programs from an OCaml program
  2015-12-14 16:40 [Caml-list] Invoking Java programs from an OCaml program Soichi Sumi
@ 2015-12-14 17:25 ` Chan Ngo
  2015-12-15  5:21   ` Paul Pelzl
  2015-12-15  9:06 ` forum
  1 sibling, 1 reply; 8+ messages in thread
From: Chan Ngo @ 2015-12-14 17:25 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1717 bytes --]

Hi,

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 <https://ocaml.github.io/ocamlunix/ocamlunix.html>

Hope that helps,

Best,

---
Chan Ngo
INRIA,
(+33)02 99 84 72 84
chan.ngo@inria.fr <mailto:chan.ngo@inria.fr>
http://people.rennes.inria.fr/Chan.Ngo <http://people.rennes.inria.fr/Chan.Ngo>


> On Dec 14, 2015, at 5:40 PM, Soichi Sumi <s-sumi@ist.osaka-u.ac.jp> wrote:
> 
> I want to invoke Java programs and use their result
> from an OCaml program in my research.
> 
> I have tried OCaml-Java to realize the integration
> and succeeded to execute some example.However,
> it cannot invoke objects defined by me, as far as
> I read OCaml-Java document. I think it only realize
> seamless integration of Java standard library and OCaml.
> 
> Is there anyway to use Java Object which defined by me
> or to invoke jar file and use the result?
> 
> If you know another way to use the result produced by
> Java programs, I want to know the way too.
> 
> Any help appreciated.
> 
> --Soichi Sumi
> --OCaml-Java HP : www.ocamljava.org <http://www.ocamljava.org/>
> 
> =========================================
> Soichi Sumi
> Graduate School of Information Science and Technology
> Osaka University
> 1-5, Yamadaoka, Suita, Osaka, Japan
> Email: s-sumi@ist.osaka-u.ac.jp <mailto:s-sumi@ist.osaka-u.ac.jp>
> =========================================


[-- Attachment #2: Type: text/html, Size: 3470 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Invoking Java programs from an OCaml program
  2015-12-14 17:25 ` Chan Ngo
@ 2015-12-15  5:21   ` Paul Pelzl
  2015-12-16 13:29     ` Chan Ngo
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Pelzl @ 2015-12-15  5:21 UTC (permalink / raw)
  To: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 790 bytes --]

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.
> 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

Paul

[-- Attachment #2: Type: text/html, Size: 1385 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Invoking Java programs from an OCaml program
  2015-12-14 16:40 [Caml-list] Invoking Java programs from an OCaml program Soichi Sumi
  2015-12-14 17:25 ` Chan Ngo
@ 2015-12-15  9:06 ` forum
  1 sibling, 0 replies; 8+ messages in thread
From: forum @ 2015-12-15  9:06 UTC (permalink / raw)
  To: Soichi Sumi; +Cc: Xavier Clerc, caml-list


> Le 14 déc. 2015 à 17:40, Soichi Sumi <s-sumi@ist.osaka-u.ac.jp> a écrit :
> 
> I want to invoke Java programs and use their result
> from an OCaml program in my research.
> 
> I have tried OCaml-Java to realize the integration
> and succeeded to execute some example.However,
> it cannot invoke objects defined by me, as far as
> I read OCaml-Java document. I think it only realize
> seamless integration of Java standard library and OCaml.

You should actually be able to use your own objects as
easily as any other Java object. It just happens that some
SDK classes can be accessed through the OCaml-Java
library.

The major point to consider is the classpath. By default,
the compiler has only access to the SDK classes, but
you can add any directory or jar file thanks to the "-cp"
command-line switch.


Hope this helps,

Xavier Clerc


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Invoking Java programs from an OCaml program
  2015-12-15  5:21   ` Paul Pelzl
@ 2015-12-16 13:29     ` Chan Ngo
  2015-12-18 10:25       ` Seungcheol Jung
  0 siblings, 1 reply; 8+ messages in thread
From: Chan Ngo @ 2015-12-16 13:29 UTC (permalink / raw)
  To: Paul Pelzl, OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1469 bytes --]


> 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 <mailto: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.
> https://ocaml.github.io/ocamlunix/ocamlunix.html <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 <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


[-- Attachment #2: Type: text/html, Size: 2814 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Invoking Java programs from an OCaml program
  2015-12-16 13:29     ` Chan Ngo
@ 2015-12-18 10:25       ` Seungcheol Jung
  2015-12-18 22:55         ` Sebastien Ferre
  2015-12-21  8:53         ` forum
  0 siblings, 2 replies; 8+ messages in thread
From: Seungcheol Jung @ 2015-12-18 10:25 UTC (permalink / raw)
  To: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 2845 bytes --]

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.
>> 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
>
>

[-- Attachment #2: Type: text/html, Size: 4446 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Invoking Java programs from an OCaml program
  2015-12-18 10:25       ` Seungcheol Jung
@ 2015-12-18 22:55         ` Sebastien Ferre
  2015-12-21  8:53         ` forum
  1 sibling, 0 replies; 8+ messages in thread
From: Sebastien Ferre @ 2015-12-18 22:55 UTC (permalink / raw)
  To: caml-list

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 <chan.ngo2203@gmail.com
> <mailto:chan.ngo2203@gmail.com>> wrote:
>
>
>>     On Dec 15, 2015, at 6:21 AM, Paul Pelzl <pelzlpj@gmail.com
>>     <mailto:pelzlpj@gmail.com>> wrote:
>>
>>     On Mon, Dec 14, 2015 at 9:25 AM, Chan Ngo <chan.ngo2203@gmail.com
>>     <mailto: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.
>>         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 <tel:%28%2B33%2902%2099%2084%2072%2084>
>     chan.ngo@inria.fr <mailto:chan.ngo@inria.fr>
>     http://people.rennes.inria.fr/Chan.Ngo
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Invoking Java programs from an OCaml program
  2015-12-18 10:25       ` Seungcheol Jung
  2015-12-18 22:55         ` Sebastien Ferre
@ 2015-12-21  8:53         ` forum
  1 sibling, 0 replies; 8+ messages in thread
From: forum @ 2015-12-21  8:53 UTC (permalink / raw)
  To: Seungcheol Jung; +Cc: OCaml Mailing List, forum

Le 18.12.2015 11:25, Seungcheol Jung a écrit :

(...)


> 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.

OCaml-Java actually compiles OCaml code to *Java* bytecode, meaning that 
no
OCaml interpreter is involved. Of course, the ocamljava-compiled 
programs are
slower than ocamlopt-compiled ones; however, the factor is heavily 
dependent
on the kind of computation.

Currently the rule of thumb is that ocamljava-compiled code is roughly 3 
times
slower, with numerical code on par and "massively functional code" much 
slower
(sometimes 10x slower).


Hope this helps,

Xavier

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-12-21  8:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-14 16:40 [Caml-list] Invoking Java programs from an OCaml program Soichi Sumi
2015-12-14 17:25 ` Chan Ngo
2015-12-15  5:21   ` Paul Pelzl
2015-12-16 13:29     ` Chan Ngo
2015-12-18 10:25       ` Seungcheol Jung
2015-12-18 22:55         ` Sebastien Ferre
2015-12-21  8:53         ` forum
2015-12-15  9:06 ` forum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).