Building a JAR with just the Gemfile gems?

38 views
Skip to first unread message

Malcolm McFarland

unread,
Jun 27, 2025, 3:50:21 PMJun 27
to JRuby project mailing list
Hey folks, 

I've been doing quite a bit of JRuby+Java work over the last several years. Recently, I needed to incorporate some Ruby code into a Scala/Maven project. Using Bundler and a post from Nick Sieger's circa 2009* as a jumping off point (I believe he's on this list too), I was able to put together a JAR that has _only_ the gems specified in the Gemfile (and their dependencies). The basic outline is: 

a) use bundler cache to pool the dependencies in a local dir
b) download/extract a JRuby tarball
c) copy the gems from the bundler cache dir into the JRuby dir
d) wrap the JRuby dir up into the final JAR

This creates a JAR that I can import into a Java or Scala project and use like any other library.

I'm using maven-antrun-plugin to do most of this step-by-step, but I know there is an ecosystem of JRuby Maven plugins out there for various tasks. So far, the closest I've found is the gem-maven-plugin, but it looks like that pulls gems down from Rubygems, and I'm including locally-built gems as well. My process does work, but it feels like a bit of a hack. Is there a JRuby+Maven plugin that accomplishes something similar?

Malcolm McFarland

unread,
Jun 28, 2025, 8:46:16 PMJun 28
to Charles Oliver Nutter, JRuby project mailing list
Hey Charles, thanks for the reply! I've come across Warbler (but not Jarbler, though they do look similar), and they appear to have a slightly different use case. I'm not really trying to make a Java executable, just a JAR library with all of the dependent gems included. This library is essentially a facade for some specialized Ruby code that we use in other parts of our system; basically keeping things DRY across languages/compilation targets. As such, this library doesn't have a Main entry point; it really is just lifting Ruby code into the JVM type system for access elsewhere (in this case, from Scala).

I'd love to chat more about our stack off-list!

Cheers,
Malcolm


On Fri, Jun 27, 2025 at 7:51 PM Charles Oliver Nutter <hea...@headius.com> wrote:
Hey Malcom! I'm not at my desk right now but I can give you a few pointers. 

In general, JRuby is pretty good at loading anything that exists in the classpath, so plain old file resources in a jar get picked up. But putting things in the right structure sometimes requires a little more work.

You might want to look at two projects: 

Warbler: a tool for building deployable web archives and executable jar files with jruby and all dependencies included in the archive. It hasn't been maintained for a while but I'm in the process of waking it up and making updates. 

Jarbler: another tool I found recently that focuses on just executable jars but it has been maintained more recently. 

There may be others on this list or others in our Matrix chat room that could offer some suggestions as well. 

I'd also be interested in having a chat about how you're using JRuby! Would you mind if I emailed you off the list and asked a few questions? I'm pushing hard on the project this year and really want to connect with users so we know how to make JRuby more efficient and more useful.

--
You received this message because you are subscribed to the Google Groups "jruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jruby+un...@g.ruby-lang.org.
To view this discussion visit https://groups.google.com/a/g.ruby-lang.org/d/msgid/jruby/CAJa2EsOSMTC0pnbYiCghGXU56KYKWsP88PaNQQCFW6LQYE05uw%40mail.gmail.com.

Mohit Sindhwani

unread,
Sep 17, 2025, 2:54:41 AMSep 17
to Malcolm McFarland, Charles Oliver Nutter, JRuby project mailing list
Hi Malcolm,

I'm late to the party and imagine that you have solved your problem.

On 2025-6-29 8:45 am, Malcolm McFarland wrote:
> Hey Charles, thanks for the reply! I've come across Warbler (but not
> Jarbler, though they do look similar), and they appear to have a
> slightly different use case. I'm not really trying to make a Java
> executable, just a JAR library with all of the dependent gems
> included. This library is essentially a facade for some specialized
> Ruby code that we use in other parts of our system; basically keeping
> things DRY across languages/compilation targets. As such, this library
> doesn't have a Main entry point; it really is just lifting Ruby code
> into the JVM type system for access elsewhere (in this case, from Scala).

I have these posts on my blog that documented how I called Java from
JRuby (using Apache POI as an example), and also how I packed an
executable JAR using JRuby.
Links:
[1] Using Apache POI from JRuby:
https://notepad.onghu.com/2021/jruby-using-apache-poi-to-generate-xlsx-files/
[2] Creating JARs:
https://notepad.onghu.com/2021/jruby-win-day2-creating-jar-files/

Hope this helps a bit.

Best regards,
Mohity.



Malcolm McFarland

unread,
Sep 17, 2025, 3:12:49 PMSep 17
to mo_...@onghu.com, JRuby project mailing list
Hey Mohity, thanks for the links. I looked at Warbler and it doesn't really fit my use case; it seems to be more of a self-contained JRuby application bundler with JRuby as the jumping off point, whereas I wanted a self-contained JAR that is treated like any other library in the JVM ecosystem. I ended up using Maven's Ant plugin to coordinate Bundler and the other file operations; been working on a blog post for a while and am hoping to have it up in the next week or so.

Cheers,
Malcolm

Mohit Sindhwani

unread,
Sep 17, 2025, 10:13:37 PMSep 17
to Malcolm McFarland, JRuby project mailing list
Hi Malcolm,

Thanks for the reply!

On 2025-9-18 3:12 am, Malcolm McFarland wrote:
> Hey Mohity, thanks for the links. I looked at Warbler and it doesn't
> really fit my use case; it seems to be more of a self-contained JRuby
> application bundler with JRuby as the jumping off point, whereas I
> wanted a self-contained JAR that is treated like any other library in
> the JVM ecosystem. I ended up using Maven's Ant plugin to coordinate
> Bundler and the other file operations; been working on a blog post for
> a while and am hoping to have it up in the next week or so.
>

I misread your original post and realise now that you're not looking for
a JRuby executable. Look forward to your post - do post a link either
here to the group, or to me personally (if you don't mind) when it's up.

Cheers,
Mohit.



Reply all
Reply to author
Forward
0 new messages