On this page:

By default, JRuby is not included in the modeling tool, however, you can add it manually. In addition, you can also install Gems for JRuby.  

Adding JRuby to the modeling tool

To add JRuby to the modeling tool


  1. Copy the JRuby engine jar file (e.g. jruby-complete-9.2.14.0.jar) to <tool_installation_directory>\plugins\com.nomagic.magicdraw.automaton\lib.
  2. Add the entry below to the file <tool_installation_directory>\plugins\com.nomagic.magicdraw.automaton\enginedescriptor.xml.

    <void method="add">
    	<object class="com.nomagic.magicdraw.automaton.EngineDescriptor">
    		<void property="extensions">
    			<object class="java.util.ArrayList">
    				<void method="add">
    					<string>rb</string>
    				</void>
    			</object>
    		</void>
    		<void property="jars">
    			<object class="java.util.ArrayList"/>
    		</void>
    		<void property="name">
    			<string>JRuby</string>
    		</void>
    	</object>
    </void>
  3. Append a library entry in file <tool_installation_directory>\plugins\com.nomagic.magicdraw.automaton\plugin.xml.

    <library name="lib/jruby-complete-9.2.14.0.jar"/>

Installing Gems for JRuby

To install a gem for Ruby engine inside MagicDraw


  1. Open the command line.
  2. Go to the folder <tool_installation_directory>\plugins\com.nomagic.magicdraw.automaton\lib.
  3. Enter the following command to install a gem.
     
java -jar jruby-complete-<version>.jar -S gem install [--user-install] <gem name1> <gem name2> ...
  • <version> is the JRuby version, e.g. 9.2.14.0.
  • <gem name> is the name of a gem.
  • The three dots (...) mean that you can type a list of gem names there.

Once the gem has been installed, you can use it in the MagicDraw Macro Engine. The example below shows how to create a macro that can generate a unique ID by using a gem.

require 'java'
require 'rubygems'
require 'uuid'
Application = com.nomagic.magicdraw.core.Application
uuid = UUID.new Application.getInstance().getGUILog().log(uuid.generate);


To install a gem for the existing Ruby environment on your machine and use it in the Macro Engine


  1. Add the following properties to specify the home and library of JRuby in <tool_installation_directory>/bin/mduml.properties under JAVA_ARGS section (assuming you have JRuby installed in C:/jruby-9.2.14.0 on your machine).
     
-Djruby.home\="C:/jruby-9.2.14.0" -Djruby.lib\="C:/jruby-9.2.14.0/lib"

For example:

..JAVA_ARGS=-Xmx800M -Djruby.home\="C:/jruby-9.2.14.0" -Djruby.lib\="C:/jruby-9.2.14.0/lib"

     2.  Change the JRuby library path to navigate to your jruby.jar in <tool_installation_directory>/plugins/com.nomagic.magicdraw.automaton/plugin.xml.

... <library name="c:/jruby-9.2.14.0/lib/jruby.jar"/>
  1. The command in this section should run in <tool_installation_directory>/plugins/com.nomagic.magicdraw.automaton/engine.
  2. If you have a whitespace in the property file path, you need to type a double quote to wrap both the property and its value, for each property, for example:
    -Djruby.home=C:/my white space/jruby-9.2.14.0" “-Djruby.lib=C:/my white space/jruby-9.2.14.0/lib