Forum: JRuby Depending on a gem in a portable app?

C31517bb2497ca20710a294d3f8d1144?d=identicon&s=25 Jonathan Coveney (Guest)
on 2012-07-19 22:47
(Received via mailing list)
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
B05d3cbc64b0031a24c2887fb6ddc173?d=identicon&s=25 kristian (Guest)
on 2012-07-19 23:06
(Received via mailing list)
maybe you want to have a look at

https://github.com/torquebox/jruby-maven-plugins/t...

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 :)

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
748797a1a0dc3de4c50e722d90589129?d=identicon&s=25 Rhett Sutphin (Guest)
on 2012-07-19 23:15
(Received via mailing list)
Hi Jon,

On Jul 19, 2012, at 3:46 PM, Jonathan Coveney 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-gemjar`[1] is an
extension for `buildr`[2] 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

[1]: https://github.com/NUBIC/buildr-gemjar
[2]: http://buildr.apache.org/
C31517bb2497ca20710a294d3f8d1144?d=identicon&s=25 Jonathan Coveney (Guest)
on 2012-07-20 02:08
(Received via mailing list)
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 Sutphin <rhett.sutphin@gmail.com>
2cda9758c673339fc208518b9756479b?d=identicon&s=25 Colin Surprenant (Guest)
on 2012-07-20 05:12
(Received via mailing list)
You can take a look into my RedStorm project
https://github.com/colinsurprenant/redstorm 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
This topic is locked and can not be replied to.