创建可部署的 JRuby JAR 文件?
我需要将 JRuby 应用程序编译成独立的 JAR 文件。我该怎么做?
I need to compile my JRuby application into a standalone JAR file. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Warbler 1.3.0 或更高版本也可用于制作可执行 JAR 文件。
快速说明。确保您在此处使用 JRuby`s gem 等:
您现在应该在当前目录中有一个
myapp.jar
文件。根据README
,您只需在lib
目录中添加所需的任何库,并使用.gemspec
或之一(或两者) Gemfile
来控制需要放入.jar
文件中的任何其他 gem。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:
You should now have a
myapp.jar
file in the current directory. According to theREADME
you just add any libraries you need in thelib
directory and use either (or both) a.gemspec
orGemfile
to control any other gems that need to be put into the.jar
file.查看 rawr。它是一个将您的应用程序打包到 JAR 文件中的 gem。
如果要进行编译以保护源代码,则必须为项目中的每个脚本生成一个
.class
文件(如/JRubyCompiler" rel="nofollow noreferrer">此处),然后将每个编译脚本
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 withfor each of the compiled scripts.
JRuby 1.6 改进了这一点。现在 wiki 的一个部分 - StandaloneJarsAndClasses - 讨论如何使用 jrubyc 生成.class 文件和独立 jar。
使用新的编译器,您可以构建 .class 文件,如 wiki 中的示例:
您可以将 jar 的入口点设置为 org.jruby.JarBootstrapMain 并添加 jar-bootstrap.rb 文件。
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:
And you can set the entrypoint for a jar to org.jruby.JarBootstrapMain and add a jar-bootstrap.rb file.
仅运行脚本:
JRuby 站点有一个可运行的 JAR 文件,您可以从 JRuby 获取该 文件下载页面。您需要 JRuby 完整的 JAR 文件。然后您可以通过执行以下操作来运行您的应用程序,
我相信您也可以从源代码构建相同的 JAR 文件。在下载的源代码中,将
Ruby 脚本完全嵌入到 JAR 文件中:在 Java 中嵌入 JRuby 是一个很好的起点。您可能需要解压
jruby-complete.jar
文件,添加具有 JRuby 脚本标注或嵌入 Ruby 代码的 Java 主类,替换清单的主类指向您的新入口点,并将其备份。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
I believe you can also build the same JAR file from source. In the downloaded source do
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.