JRuby: Using locally built JRuby JARs with Warbler

If you decide to rebuild JRuby locally and want to use Warbler to create an executable JAR with the newly built JRuby, it’s not obvious what you should do. This post provides one way to manage this.

The story so far. On this site, we have covered a few JRuby-related topics so far:

When you make changes to JRuby yourself or you want to be able to try something with a new version of JRuby, you realise that there is a small problem if you want to create an executable JAR using Warbler – it uses an older different version of the JRuby JARs.

Note: Before you get started, let’s assume that you have followed the steps to build JRuby and have added the JRuby bin folder to your PATH.

OK, so this is how you would install warbler

$ jruby -S gem install warbler
Fetching warbler-2.0.5.gem
Fetching jruby-jars-9.2.19.0.gem
Successfully installed jruby-jars-9.2.19.0
Successfully installed warbler-2.0.5
Parsing documentation for jruby-jars-9.2.19.0
Installing ri documentation for jruby-jars-9.2.19.0
Parsing documentation for warbler-2.0.5
Installing ri documentation for warbler-2.0.5
Done installing documentation for jruby-jars, warbler after 3 seconds
2 gems installed

Our problem happens because of this:

Fetching jruby-jars-9.2.19.0.gem
Successfully installed jruby-jars-9.2.19.0

Warbler installs jruby-jars-9.2.19.0.gem and uses this when you try to build an executable JAR. Head on over to the project that you want to package and do this.

$ jruby -S warble runnable jar
Creating project1.jar

If you open the JAR file in the 7-ZIP archive viewer, you will see that it packaged the 9.2.19 gems rather than the latest versions you built locally.

Let’s fix it!

The fix is actually [fortunately] rather simple. There are only two simple steps:

  • Rebuild jruby-jars locally first
  • Install the locally build jruby-jars

Then, use Warbler again.

Rebuild jruby-jars

Invoke a maven build for just jruby-jars by doing this.

$ mvnw clean install -Pjruby-jars -o
...
[INFO] Reactor Summary for JRuby 9.3.0.0-SNAPSHOT:
[INFO]
[INFO] JRuby .............................................. SUCCESS [  0.940 s]
[INFO] JRuby Base ......................................... SUCCESS [01:40 min]
[INFO] JRuby Core ......................................... SUCCESS [ 15.217 s]
[INFO] JRuby Lib Setup .................................... SUCCESS [01:35 min]
[INFO] JRuby Artifacts .................................... SUCCESS [  0.058 s]
[INFO] JRuby Jars Gem ..................................... SUCCESS [ 33.705 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Once you get all green on the build, you are good to go!

Install the locally built gem

You will see that the gem is at: maven\jruby-jars\pkg and you can install the local gem by doing this:

jruby -S gem install maven\jruby-jars\pkg\jruby-jars-9.3.0.0.SNAPSHOT.gem --local
Successfully installed jruby-jars-9.3.0.0.SNAPSHOT
Parsing documentation for jruby-jars-9.3.0.0.SNAPSHOT
Installing ri documentation for jruby-jars-9.3.0.0.SNAPSHOT
Done installing documentation for jruby-jars after 2 seconds
1 gem installed

List the jruby-jars gem and you will see it there:

$ jruby -S gem list jruby-jars
*** LOCAL GEMS ***
jruby-jars (9.3.0.0.SNAPSHOT, 9.2.19.0)

Tip: If you need to delete the installed gem, you can do jruby -S gem unins jruby-jars and you will be prompted which version to remove.

Build with warbler again

Now, when you use warbler again, it will package the new jruby-jars.

>jruby -S warble runnable jar
Creating project1.jar

If you open the JAR file in the 7-ZIP archive viewer, you will see that it [finally] packaged the 9.3.0.0-snapshot gems.

That’s all there is to it! I have not found a good way to speed up the process of doing the update since you need to rebuild jruby-jars and also install the gem each time you make a change. If you know a better way, let me know. If I find out, I will update the post.

I hope you find it useful. If you have any other relevant information, please let me know below and I will add it in.

comments powered by Disqus