JRuby can access classes implemented in pure Java code. Clojure can generate a class file. Therefore it's straightforward for JRuby to access classes implemented in Clojure.
First I define a class with a method in plain Java.
and compile it.
$ javac MrJava.java
Now you have MrJava.class.
Next I defina class with a method in Clojure.
This is almost equivalent to the previous code. Try compiling it.
$ java -cp ~/git/clojure/clojure.jar:. clojure.main -e "(compile 'MsClojure)"
Note that you specified your own clojure.jar. Nou you have
Try combining them with JRuby!
and run by:
$ jruby -J-cp ~/git/clojure/clojure.jar:classes:.
then you will get the following message.
Good afternoon Ujihisa, how are you? Hey Ujihisa!
- It doesn't change
$: << '~/git/clojure/clojure.jar'in JRuby file. You have to give classpath by command line option.