1. Exerb简介
Exerb是一个将ruby脚本程序(.rb)转换成Windows应用程序(.exe)的软件。目前最新版本4.1.0,下载地址:http://downloads.sourceforge.jp/exerb/23470/exerb-4.1.0.zip。
2.安装
把下载的zip文件解压,进入exerb目录,运行ruby setup.rb。这时exerb和mkexy命令将会加入ruby/bin目录中。
3.ruby -> exe
先来个最简单的
hello.rb
- puts 'Exerb'
运行exerb hello.rb,生成一个hello.exe文件,OK。
下面写个GUI程序,使用wxRuby类库。
hello_wx.rb
- require 'wxruby'
- include Wx
- class MyFrame < Frame
- def initialize(title)
- super(nil, -1, title)
- Button.new(self, -1, "Hello, I'm a Button")
- end
- end
- class MyApp < App
- def on_init
- frame = MyFrame.new('Simple wxRuby App')
- frame.show
- end
- end
- a = MyApp.new
- a.main_loop
exerb hello_wx.rb,生成hello_wx.exe,却不能运行。因为exe并没有把程序所需的类库打包进来,这时候就得执行mkexy命令。
mkexy hello_wx.rb,生成hello_wx.exy文件
hello_wx.exy
- # Generated by mkexy
- # on 2007-01-31 23:50
- general:
- startup: hello_wx.rb
- core: cui
- kcode: none
- file:
- hello_wx.rb:
- rbconfig.rb:
- file: c:/ruby/lib/ruby/1.8/i386-mswin32/rbconfig.rb
- rubygems/rubygems_version.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/rubygems_version.rb
- rbconfig/datadir.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rbconfig/datadir.rb
- rubygems/user_interaction.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/user_interaction.rb
- forwardable.rb:
- file: c:/ruby/lib/ruby/1.8/forwardable.rb
- digest.so:
- file: c:/ruby/lib/ruby/1.8/i386-mswin32/digest.so
- type: extension-library
- digest/sha2.so:
- file: c:/ruby/lib/ruby/1.8/i386-mswin32/digest/sha2.so
- type: extension-library
- rational.rb:
- file: c:/ruby/lib/ruby/1.8/rational.rb
- date/format.rb:
- file: c:/ruby/lib/ruby/1.8/date/format.rb
- parsedate.rb:
- file: c:/ruby/lib/ruby/1.8/parsedate.rb
- time.rb:
- file: c:/ruby/lib/ruby/1.8/time.rb
- rubygems/source_index.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb
- rubygems/version.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/version.rb
- rubygems/specification.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb
- openssl.so:
- file: c:/ruby/lib/ruby/1.8/i386-mswin32/openssl.so
- type: extension-library
- openssl/bn.rb:
- file: c:/ruby/lib/ruby/1.8/openssl/bn.rb
- openssl/cipher.rb:
- file: c:/ruby/lib/ruby/1.8/openssl/cipher.rb
- openssl/digest.rb:
- file: c:/ruby/lib/ruby/1.8/openssl/digest.rb
- openssl/buffering.rb:
- file: c:/ruby/lib/ruby/1.8/openssl/buffering.rb
- fcntl.so:
- file: c:/ruby/lib/ruby/1.8/i386-mswin32/fcntl.so
- type: extension-library
- openssl/ssl.rb:
- file: c:/ruby/lib/ruby/1.8/openssl/ssl.rb
- openssl/x509.rb:
- file: c:/ruby/lib/ruby/1.8/openssl/x509.rb
- openssl.rb:
- file: c:/ruby/lib/ruby/1.8/openssl.rb
- rubygems/gem_openssl.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/gem_openssl.rb
- rubygems/security.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/security.rb
- rubygems/custom_require.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb
- rubygems.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems.rb
- ubygems.rb:
- file: c:/ruby/lib/ruby/site_ruby/1.8/ubygems.rb
- wxruby.so:
- file: c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt/wxruby.so
- type: extension-library
该文件把hello_wx.rb所需的类库文件都包含进来了。
运行exerb hello_wx.exy,这时候生成的hello_wx.exe是可以执行的,问题是打开文件的同时会打开一个控制台窗口,要解决这个问题,就得修改hello_wx.exy文件,把cui改成gui。
- general:
- startup: hello_wx.rb
- core: gui #cui
- kcode: none
再次运行exerb hello_wx.exy,生成一个红宝石图标的exe文件,OK!
另外,exy文件中还可以设置图标和版本信息。不再赘述。配置属性如下:
- resource:
- icon:
- - width : 16
- height: 16
- color : 4
- file : your_ico.ico
- - width : 32
- height: 32
- color : 4
- file : your_ico.ico
- version:
- file_version_number : 1.2.3.4
- product_version_number: 5.6.7.8
- comments : Comments Field
- company_name : Company Name Field
- legal_copyright : Legal Copyright Field
- legal_trademarks : Legal Trademarks Field
- file_version : File Version Field
- product_version : Product Version Field
- product_name : Product Name Field
- file_description : File Description Field
- internal_name : Internal Name Field
- original_filename : Original Filename Field
- private_build : Private Build Field
- special_build : Special Build Field