To install a gem for Ruby engine inside MagicDraw
- Open command line.
- Go to folder <MagicDraw folder>\plugins\com.nomagic.magicdraw.automaton\engines.
- 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 version of the JRuby, for example, 1.5.1 or 1.6.7.2.
- <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 MagicDraw Macro Engine, for example
require 'java' require 'rubygems' require 'uuid' Application = com.nomagic.magicdraw.core.Application uuid = UUID.new Application.getInstance().getGUILog().log(uuid.generate);
The above example shows how to create a macro that can generate a unique ID by using a gem.
To install a gem for the existing Ruby environment on your machine and use it in Macro Engine
- Add the following properties to specify the home and library of JRuby in <MagicDraw>/bin/mduml.properties under JAVA_ARGS section (assuming you have JRuby installed in C:/jruby-1.5.3 on your machine).
-Djruby.home\="C:/jruby-1.5.3" -Djruby.lib\="C:/jruby-1.5.3/lib"
For example:
..JAVA_ARGS=-Xmx800M -Djruby.home\="C:/jruby-1.5.3" -Djruby.lib\="C:/jruby-1.5.3/lib"
2. Change the JRuby library path to navigate to your jruby.jar in <MDdir>/plugins/com.nomagic.magicdraw.automaton/plugin.xml.
... <library name="c:/jruby-1.5.3/lib/jruby.jar"/>
- The command in this section should run in <MDdir>/plugins/com.nomagic.magicdraw.automaton/engine.
- 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-1.5.3" “-Djruby.lib=C:/my white space/jruby-1.5.3/lib”