Depending on a gem in a portable app?

For context, I have a Java class which uses a ScriptingContainer to run
some JRuby code. That JRuby code depends on the openssl gem, so my goal
is
to figure out how I can depend on that openssl gem in a portable way.

I have a couple of options… this code lives in a jar. Is there a place
where I can put the openssl gem jar (how do I get that? maven would be
great but I doubt it is that easy) in the jar so that “require
‘openssl’”
works? Generally, where does jruby look for gems if it is embedded in
Java
code?

Thanks for the help
Jon

maybe you want to have a look at

https://github.com/torquebox/jruby-maven-plugins/tree/master/gem-assembly-descriptors/src/it/assemble-project-with-gems

which shows how to build executable uber-jar with jruby-complete.jar
and jars and gems and allows you to execute the “executables” from the
package gems.

$ java -jar my.jar heroku # in case you have heroku gem included :slight_smile:

if you just want to add gems to the jar with maven:

  • add the gems artifacts to your pom
  • add the ‘target/rubygems’ directory as build/resource including
    “gems” and “specifications” directory

then maven will build a jar where the ScriptingContainer will find the
gems (after require ‘rubygems’).

if you just want to use gems with ScriptingContainer during testing
the respective build/resource is already set by the gem-maven-plugin.
so just adding gem artifacts s sufficient.

if you need more help - please let me know.

regards,
Kristian

Hi Jon,

On Jul 19, 2012, at 3:46 PM, Jonathan C. wrote:

For context, I have a Java class which uses a ScriptingContainer to run some
JRuby code. That JRuby code depends on the openssl gem, so my goal is to figure
out how I can depend on that openssl gem in a portable way.

I have a couple of options… this code lives in a jar. Is there a place where I
can put the openssl gem jar (how do I get that? maven would be great but I doubt
it is that easy) in the jar so that “require ‘openssl’” works? Generally, where
does jruby look for gems if it is embedded in Java code?

Thanks for the help
Jon

You can package gems in a jar. My project buildr-gemjar1 is an
extension for buildr2 which handles this for you, including
installing all dependencies and flattening contained jars. Its
documentation also includes some links to the theory behind this so you
could roll your own solution.

Rhett

Thank you both for your response. Perhaps I should explain more about
how
my build system works.

I wanted to pull from maven, but it isn’t mavenized. It uses ivy to pull
maven dependencies, and ant to manage the build. There are a mish-mash
of
projects (unideal, but this is how it is). So currently jruby is a
dependency in this project, and the code lives there. So the
dependencies
are packaged into the same jar as the dependent code via ant.

The buildr approach seems elegant, but switching my build system is not
possible. Does it integrate with ant?

I don’t necessarily like the idea of having to package my own jruby +
gems,
but if I have to do that I have to do that. Preferable would be
depending
on JRuby externally, and some methodology for pulling down the gem jar
(which could be packaged in my repo, I suppose) and putting it in the
jar
where it needs to be.

What I want to avoid is: a) complicating my build file in a big way and
b)
having to include jruby in my repo.

Do you think this is possible? Where in the jar does the actual gem jar
need to be so that I can use it?

Jon

2012/7/19 Rhett S. [email protected]

You can take a look into my RedStorm project
GitHub - colinsurprenant/redstorm: JRuby on Storm which provides the JRuby
glue & a DSL for the Twitter Storm project. Basically, a single jar
file must be submitted to a Storm cluster so RedStorm builds a jar
file with all Java and JRuby dependencies and required gems.

If you take a look into redstorm/lib/tasks/red_storm.rake you will
find the tasks to layout all the dependencies into a target/ directory
and jar it up. It uses Ant and Ivy (using the pompompom gem) and for
the gems, it depends on Bundler, the gems required for the jar file
must be included in a Bundler group. The idea here is that gems are
installed locally using Bundler and the installed gems are copied
in the target/ directory to be included in the jar.

Once you application is fired, you can setup ENV[“GEM_PATH”] and
ENV[“GEM_HOME”] to the path to your gems in the jar file - see
redstorm/lib/red_storm/environment.rb.

Hope this helps.

Colin