Calling Julia from Java

1,520 views
Skip to first unread message

Peilun Li

unread,
Jul 14, 2015, 7:49:37 AM7/14/15
to julia...@googlegroups.com
Hi,

I'm trying to call Julia functions from Java. Limited by the project, it is not a good idea to use Java JNI to call a C function that calls Julia.

Is there any relatively direct way to call Julia from Java?  I need to not only call Julia functions from Java, but also pass input data and retrieve output answers.

Thanks,
Peilun

Isaiah Norton

unread,
Jul 14, 2015, 9:24:29 AM7/14/15
to julia...@googlegroups.com
You may need to roll your own as I haven't heard of any existing solutions. Two possible approaches:

- expose Julia functionality via RPC / network / etc. using ZMQ or similar.

- call the Julia embedding API directly (JNA is likely sufficient -- no intermediate C):
  You might be able to do some bootstrap or marshalling with JavaCall:

  node-julia is probably the largest example of the embedding API in-use:

Avik Sengupta

unread,
Jul 14, 2015, 10:21:26 AM7/14/15
to julia...@googlegroups.com
Yes to everything Isaiah said. 

If you cannot use JNI at all, then doing a network wrapper is your only option. The simplest way is to use https://github.com/tanmaykm/JuliaWebAPI.jl/ 

If your concern is merely writing C glue code, but you are happy to use JNI to call Julia functions directly, then that is a good possibility. JavaCall currently focusses on calling Java from C, but the JNI API is the same both ways. Which means you can use the code in JavaCall to make things easier. In particular, JavaCall will give you the representation of JNIEnv on the Julia side, and conversion functions from basic Java types to Julia types. Which means that once you call into the Julia function, you can then access java parameters and return Julia values back to java. All in all, it should simple to do all that ... I haven't done it yet since I don't need that functionality myself. 

Regards
-
Avik
Reply all
Reply to author
Forward
0 new messages