Software engineer, data guy, Open Source enthusiast, New Hampshire resident, husband, father. Fan of guitars, hiking, photography, homebrewing, sarcasm.
Ahead-of-time compiling JRuby, packaging a Java Jar, creating a Gemspec, using Warbler
In this blog post I’ll share some code to demonstrate ahead-of-time compiling and packaging JRuby code into a standalone Java Jar. This functionality is nice if you develop locally via RVM, and want to deploy to a JVM server.
Created file:.ruby-version
Created file: .ruby-gemset
Created file: Gemfile
Executed bundle to install required gems
Created main module, file: lib/jruby-jar-example.rb
Created sample class, file: lib/jruby-jar-example/some_class.rb
Created main bin file, file: bin/jruby-jar-example-main.rb. This file will be the main bin file that drives the Jar execution.
Created a gemspec file, file: jruby-jar-example.gemspec
[Optional] Now that the gemspec defines the project, it can be built and tested via IRB:
Warbler will use a gemspec if it exists. If you didn’t create one, or need to modify additional settings, you can execute “warble config” to generate a config/warble.rb file to override project settings.
At this point the code can be compiled and packaged into a Java jar using warble:
Your Jar can now be executed or deployed to a JVM: