Ruby代码到JAR [英] Ruby code to JAR

查看:114
本文介绍了Ruby代码到JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将ruby程序编译为java JAR程序。我查看了JRuby并看到了几个能够eval()ruby代码的Java应用程序示例,但是有一个更优雅的解决方案,允许简单地编写ruby中的所有内容,然后直接将批量编译成JAR文件吗? / p>

这背后的总体目标是能够扩展名为Burp Proxy的安全工具。所以我希望能够使用我所有的Ruby测试脚本(显然是组织它们以便它们与Burp扩展器连接)并将我的插件编译成可以由该工具执行的JAR文件。



如果您可以在答案中包含一些示例或链接,甚至会更好!



感谢您的时间。

解决方案

JRuby允许您编译为.class文件,您可以正常查看。你只需要包含jruby.jar。来自此处


运行AOT
编译器的典型方法是运行



jrubyc<脚本名称>



或者,在Microsoft Windows上:



jruby -S jrubyc< script name>



此命令在
中输出.class文件当前目录中包含父
目录和包匹配文件所在的
。所以以下
命令



jrubyc foo / bar / test.rb



将输出



foo / bar / test.class



要运行
编译器生成的文件,请在
当前目录(父目录$)中使用-cp(类
searchpath)参数b $ b表示上面的foo / bar / test.class)和jruby.jar的
路径,并以
执行它你将是一个名为
foo.bar.test的普通Java类:



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



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.

解决方案

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

这篇关于Ruby代码到JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆