Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby code to JAR

Tags:

java

ruby

jar

jruby

I'd like to be able to compile a ruby program to a java JAR program. I've looked into JRuby and seen several examples of Java applications that would be able to eval() ruby code, but is there a more elegant solution allowing to simply code everything in ruby and then compile the lot directly to a JAR file?

The overall goal behind that is to be able to extend a security tool called Burp Proxy. So I'd like to be able to use all my Ruby pentesting scripts (obviously organising them so they interface with Burp extender) and compile my plugins to JAR file that can be executed by the tool.

If you could include some examples or links to examples in your answer that would even be better!

Thanks for your time.

like image 963
Benjamin Avatar asked Jul 23 '09 04:07

Benjamin


1 Answers

JRuby allows you to compile to .class files, which you can jar up normally. You'll just have to include jruby.jar as well. From here:

The typical way to run the AOT compiler is to run

jrubyc <script name>

Or, on Microsoft Windows:

jruby -S jrubyc <script name>

This command outputs a .class file in the current directory with parent directories and package matching where the file lives. So the following command

jrubyc foo/bar/test.rb

will output

foo/bar/test.class

To run the file produced by the compiler, use the -cp (class searchpath) parameter with both the current directory (parent directory for foo/bar/test.class above) and the path to jruby.jar, and execute it as you would a normal Java class named foo.bar.test:

java -cp .:/path/to/jruby.jar foo.bar.test

like image 88
Pesto Avatar answered Nov 02 '22 03:11

Pesto