Create deployable JRuby JAR file?

Viewed 16619

I need to compile my JRuby application into a standalone JAR file. How can I do this?

4 Answers

Check out rawr. It is a gem that packages your application in a JAR file.

If you want to compile for source code protection you must produce a .class file for each script in your project (as described here) and then replace the contents of the original script with

require 'the_corresponding_class_file'

for each of the compiled scripts.

To just run a script:

The JRuby site has a runnable JAR file that you can get at the JRuby download page. You want the JRuby complete JAR file. You can then run your application by doing

java -jar jruby-complete-1.4.0.jar <script>

I believe you can also build the same JAR file from source. In the downloaded source do

ant --projecthelp

To embed a Ruby script completely into a JAR file: Embedding JRuby in Java is a good starting point. You will probably want to unjar the jruby-complete.jar file, add your Java main class that either has the a callout to a JRuby script or has the Ruby code embedded in it, replace the manifest's main class to point to your new entry point, and jar it back up.

Related