Install Javonet for Ruby
Javonet is available as a Ruby gem package, which can be installed using Ruby package manager or any other method which supports Ruby gem packages. For applications using Ruby 2.7 and higher use javonet-ruby-sdk Package
Activate Javonet
Use register or log in pages to obtain license key. An e-mail and license key is necessary to activate Javonet.
First sample application
Javonet needs to be imported as any other dependency.
require 'javonet-ruby-sdk'
Javonet needs to be activated first. Activation must be called only once at the start-up of an application. During the first activation, license server are called and a javonet.lic file is generated.
Javonet.activate("your-license-key")
To use other programming technology, Runtime Context of the called technology needs to be created.
python_runtime = Javonet.in_memory.python
RuntimeContext refers to single instance of the called runtime. Once it is created it is used to interact with called runtime. The simplest use case is to get from target technology a type from a built-in library:
python_type = python_runtime.get_type("math").execute
And then get static field from the type:
response = python_type.get_static_field("pi").execute
The returned value needs to be cast to calling technology type and can be used as any other variable:
result = response.get_value
puts result
To sum up, the whole code snippet looks like:
# <Activation>
Javonet.activate("your-license-key")
# </Activation>
# <RuntimeContextCreation>
python_runtime = Javonet.in_memory.python
# </RuntimeContextCreation>
# <GetType>
python_type = python_runtime.get_type("math").execute
# </GetType>
# <GetStaticField>
response = python_type.get_static_field("pi").execute
# </GetStaticField>
# <GetValue>
result = response.get_value
puts result
# </GetValue>
Was this article helpful?