文章目录
  1. 1. 使用介绍
  2. 2. 实例
  3. 3. 注意事项

淘汰bat/vbs/js吧!

OCRA是一个一键式Ruby打包工具,可以将Ruby脚本及所需环境构建为一个单独的Exe文件发布,用户环境上没有Ruby也可以运行!在公司内部作为小工具使用特别方便。

功能:

  • LZMA压缩(可选,默认打开)
  • 支持Ruby 1.8.7 / 1.9.3 / 2.0.0 ( 通过RubyInstaller安装的版本 )
  • 支持命令行和视窗模式
  • 根据使用包含gem包,或者从gemfile包含gem包

OCRA下载:传送门

使用介绍

ocra的使用方式很简单,只要安装了ocra之后,执行

1
ocra script.rb

即可生成script.exe文件,包含script.rb文件,Ruby解释器和所有的依赖项(DLL文件和gem包)。

实例

test.rb文件打包,生成print_time.exe文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
d:\work\open_source\personal_blog\gem_roadmap\problem>ocra D:\temp\test.rb --output D:\temp\print_time.exe
=== Loading script to check dependencies
********************
Time.now = 2014-02-07 16:52:37 +0800
Time.now = 2014-02-07 16:52:37 +0800
Time.now = 2014-02-07 16:52:38 +0800
Time.now = 2014-02-07 16:52:38 +0800
Time.now = 2014-02-07 16:52:38 +0800
Time.now = 2014-02-07 16:52:38 +0800
Time.now = 2014-02-07 16:52:38 +0800
Time.now = 2014-02-07 16:52:39 +0800
Time.now = 2014-02-07 16:52:39 +0800
Time.now = 2014-02-07 16:52:39 +0800
********************
=== Including 53 encoding support files (3194880 bytes, use --no-enc to exclude)
DL is deprecated, please use Fiddle
=== Building D:/temp/print_time.exe
=== Adding user-supplied source files
=== Adding ruby executable ruby.exe
=== Adding detected DLL C:/Ruby200/bin/zlib1.dll
=== Adding detected DLL C:/Ruby200/bin/LIBEAY32.dll
=== Adding detected DLL C:/Ruby200/bin/SSLEAY32.dll
=== Adding detected DLL C:/Ruby200/bin/libffi-6.dll
=== Adding library files
=== Compressing 10006304 bytes
=== Finished building D:/temp/print_time.exe (2518489 bytes)

运行后即可生成print_time.exe文件,此文件可以在没有安装Ruby的机器中运行。

注意事项

1.9.3之后的RubyInstaller不支持WindowsXPWindows2003。如果要支持老版本Windows(公司内部很常见),请制作EXE文件时选择1.9.3版本的Ruby。

文章目录
  1. 1. 使用介绍
  2. 2. 实例
  3. 3. 注意事项