Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create deployable JRuby JAR file?

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

like image 649
PythonGem Avatar asked Feb 15 '10 21:02

PythonGem


3 Answers

Warbler 1.3.0 or newer can also be used to make an executable JAR file.

Quick instructions. Make sure you're using JRuby`s gem, etc. here:

$ gem install warbler
$ mkdir bin
$ cat <<EOF > bin/myapp
#!/usr/bin/env jruby

puts "Hello World"

EOF
$ chmod a+x bin/myapp
$ warble jar

You should now have a myapp.jar file in the current directory. According to the README you just add any libraries you need in the lib directory and use either (or both) a .gemspec or Gemfile to control any other gems that need to be put into the .jar file.

like image 63
docwhat Avatar answered Oct 11 '22 21:10

docwhat


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.

like image 45
clyfe Avatar answered Oct 11 '22 23:10

clyfe


JRuby 1.6 improved this. There's now a section of the wiki - StandaloneJarsAndClasses - that talks about how to use jrubyc to generate .class files and standalone jars.

With the new compiler, you can build .class files like this example from the wiki:

james@gealach:/tmp/fnx$ cat my_foo.rb 
class Foo
   def bar(a, b)
     puts a + b
   end
 end
james@gealach:/tmp/fnx$ ~/jruby/bin/jrubyc --javac my_foo.rb 
Generating Java class Foo to C:/cygwin/tmp/fnx/Foo.java
javac  -d C:/cygwin/tmp/fnx -cp C:/cygwin/home/james/jruby/lib/jruby.jar;. C:/cygwin/tmp/fnx/Foo.java
james@gealach:/tmp/fnx$ ls
Foo.class  Foo.java  my_foo.rb
james@gealach:/tmp/fnx$ javap.exe Foo
Compiled from "Foo.java"
public class Foo extends org.jruby.RubyObject{
    public static org.jruby.runtime.builtin.IRubyObject __allocate__(org.jruby.Ruby, org.jruby.RubyClass);
    public Foo();
    public java.lang.Object bar(java.lang.Object, java.lang.Object);
    static {};
}

And you can set the entrypoint for a jar to org.jruby.JarBootstrapMain and add a jar-bootstrap.rb file.

like image 2
James Moore Avatar answered Oct 11 '22 21:10

James Moore