Creating gems-wrappers for executable java jars

Today I want to share little trick that lets us to use ruby distribution system (rubygems) as delivery mechanism for java libraries/executables. The idea was borrowed from redcar project which in turn was borrowed/extracted from ruby-processing gem. I am trying to extract important logic into separate jar_wrapper gem, so it can be easily used in any ruby project.

Install jar_wrapper with this command:

$ gem install jar_wrapper

Now you can use it in your program directly or create gem for delivering java jar file(s). For example, this code will upload remote file:

require 'jar_wrapper'

wrapper =
wrapper.java_opts = ["-Xmx1024m", "-Xss1024k" ]

# install jar file from source URL into target file:

source = ""
target = ""

wrapper.install source, target

You can aldo execute jar file (a.k.a. “java -jar jar_file.jar”)

wrapper.jar_file = "jar_file.jar"

Or you can execute java jar file by specifying main class (a.k.a. “java -cp someclasspath main_class”):

wrapper.classpath = "some_class_path"
wrapper.main_class = "main_class"

If you need more details on how to use it for practical gem, visit selenium gem. This gem downloads and create launcher for standalone selenium server.