Can anyone point me to a tutorial or guide on how to bundle up a set of
gems
into a Java project? For instance, in Maven, I can include the
jruby-complete.jar in my pom.xml, but since the wealth of the Ruby
community
is a ‘gem install’ away, I would like to include a gem or two in my
Java/Maven projects as well.
Can anyone point me to a tutorial or guide on how to bundle up a set of gems
into a Java project? For instance, in Maven, I can include the
jruby-complete.jar in my pom.xml, but since the wealth of the Ruby community
is a ‘gem install’ away, I would like to include a gem or two in my
Java/Maven projects as well.
Anyone have any tips?
You could try building a gem-jar 1 and including that in your
classpath or Maven project.
That is neat. To take it the last step, is there a way to make it so
that I
don’t have to pass the -S <parameter>, such that I could create an
executable jar that would just run the script by default?
So, if I create a .jar out of some gems, then install that to my Maven
repo
(and declare in my POM), that would be all I would need for those gems
to be
discoverable in a ScriptContainer?
Warbler 1.3.0 will support this. There’s a pre-release version on
Rubygems (install with --pre), and I hope to have 1.3.0 final released
soon.
There isn’t an easy way to do this in JRuby at this point, but you
could create your own main class that manipulates the String[] args
array and then calls org.jruby.Main and set your custom main class in
the jar’s manifest file.
...
org.jruby
jruby-complete
1.6.0.RC1
compile
ruby
http-gems
1.0.0
system
${basedir}/src/main/resources/http-gems-1.0.0.jar
For the Ruby classes, I put them in src/main/resources/ruby, and from
there
it was simply a matter of changing the App.java stub a bit to call the
script. This doesn’t use warbler, but it works simple enough without
it:
*/
public class App
{
public static void main( String[] args )
{
ScriptingContainer container = new ScriptingContainer();
URL ruby_http_app =
container.getClass().getClassLoader().getResource(“http-thing.rb”);
Object x = container.runScriptlet(PathType.CLASSPATH,
“ruby/http-thing.rb”);
System.out.println(x);
}
}
Now I have also stumbled on mkristian’s jruby maven plugins which I will
be
digging into a bit further. I wouldn’t be surprised if he didn’t figure
out
a much smoother way of doing all of this using a plugin: https://github.com/mkristian/jruby-maven-plugins
http://torquebox.org/ - A JBoss AS environment to run Rails apps
out
of, using JRuby
I also recommend the newly released book Using
JRubyhttp://pragprog.com/titles/jruby/using-jruby.
I’m only a few chapters into it, but this book is a serious goldmine of
information. Incredibly good stuff in there and absolutely worth
purchasing.
Thanks, Nick. I didn’t know about systemPath in Maven, that’s handy
Ultimately what we’re trying to do is create a jar that we can run our
rails
app out of. Something where we could do something like:
java -jar jruby-with-gems.jar -S rake test
or
java -jar jruby-complete.jar -rrails-gems.jar -S rake test
Ultimately we want to be able to host the app in a ScriptingContainer.
This
works perfectly fine with jruby-complete.jar in the classpath, and a
ScriptingContainer with jruby home set to a directory on disk will all
the
necessary gems but not when trying to pack the gems in a jar and run
without
a jruby home from the filesystem.
I tried both approaches (adding the gems to the jruby-complete jar and
using
a separate jar with just the gems in it) and neither seems to work when
trying to ‘-S rake test’ or just ‘-S rails MyApp’. Here’s a set of
commands
that doesn’t work that I would expect to work:
In particular, I don’t get why the last command (-S rails MyApp) fails
with
“No such file or directory – rails” when the next to last command
produces
output very similar to this:
It looks like the -S flag doesn’t look inside gem bin directories in
jars
the same way it does in gem directories on the file system. I’ll
continue
investigating now but wanted to tap the group for knowledge.
Cheers!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.