当前位置: 首页 > 工具软件 > Exerb > 使用案例 >

Ruby转Exe -- Exerb研究

艾弘义
2023-12-01

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

  1. puts 'Exerb'

运行exerb hello.rb,生成一个hello.exe文件,OK。

下面写个GUI程序,使用wxRuby类库。

hello_wx.rb

  1. require 'wxruby'
  2. include Wx
  3. class MyFrame < Frame
  4.    def initialize(title)
  5.      super(nil, -1, title)
  6.      Button.new(self, -1, "Hello, I'm a Button")
  7.    end
  8. end
  9. class MyApp < App
  10.    def on_init
  11.      frame = MyFrame.new('Simple wxRuby App')
  12.      frame.show
  13.    end
  14. end
  15. a = MyApp.new
  16. a.main_loop

exerb hello_wx.rb,生成hello_wx.exe,却不能运行。因为exe并没有把程序所需的类库打包进来,这时候就得执行mkexy命令。

mkexy hello_wx.rb,生成hello_wx.exy文件

hello_wx.exy

  1. # Generated by mkexy
  2. # on 2007-01-31 23:50
  3. general:
  4.   startup: hello_wx.rb
  5.    core: cui
  6.    kcode: none
  7. file:
  8.    hello_wx.rb:
  9.    rbconfig.rb:
  10.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/rbconfig.rb
  11.    rubygems/rubygems_version.rb:
  12.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/rubygems_version.rb
  13.    rbconfig/datadir.rb:
  14.      file: c:/ruby/lib/ruby/site_ruby/1.8/rbconfig/datadir.rb
  15.    rubygems/user_interaction.rb:
  16.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/user_interaction.rb
  17.    forwardable.rb:
  18.      file: c:/ruby/lib/ruby/1.8/forwardable.rb
  19.    digest.so:
  20.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/digest.so
  21.      type: extension-library
  22.    digest/sha2.so:
  23.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/digest/sha2.so
  24.      type: extension-library
  25.    rational.rb:
  26.      file: c:/ruby/lib/ruby/1.8/rational.rb
  27.    date/format.rb:
  28.      file: c:/ruby/lib/ruby/1.8/date/format.rb
  29.    parsedate.rb:
  30.      file: c:/ruby/lib/ruby/1.8/parsedate.rb
  31.    time.rb:
  32.      file: c:/ruby/lib/ruby/1.8/time.rb
  33.    rubygems/source_index.rb:
  34.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb
  35.    rubygems/version.rb:
  36.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/version.rb
  37.    rubygems/specification.rb:
  38.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb
  39.    openssl.so:
  40.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/openssl.so
  41.      type: extension-library
  42.    openssl/bn.rb:
  43.      file: c:/ruby/lib/ruby/1.8/openssl/bn.rb
  44.    openssl/cipher.rb:
  45.      file: c:/ruby/lib/ruby/1.8/openssl/cipher.rb
  46.    openssl/digest.rb:
  47.      file: c:/ruby/lib/ruby/1.8/openssl/digest.rb
  48.    openssl/buffering.rb:
  49.      file: c:/ruby/lib/ruby/1.8/openssl/buffering.rb
  50.    fcntl.so:
  51.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/fcntl.so
  52.      type: extension-library
  53.    openssl/ssl.rb:
  54.      file: c:/ruby/lib/ruby/1.8/openssl/ssl.rb
  55.    openssl/x509.rb:
  56.      file: c:/ruby/lib/ruby/1.8/openssl/x509.rb
  57.    openssl.rb:
  58.      file: c:/ruby/lib/ruby/1.8/openssl.rb
  59.    rubygems/gem_openssl.rb:
  60.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/gem_openssl.rb
  61.    rubygems/security.rb:
  62.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/security.rb
  63.    rubygems/custom_require.rb:
  64.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb
  65.    rubygems.rb:
  66.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems.rb
  67.    ubygems.rb:
  68.      file: c:/ruby/lib/ruby/site_ruby/1.8/ubygems.rb
  69.    wxruby.so:
  70.      file: c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt/wxruby.so
  71.      type: extension-library

该文件把hello_wx.rb所需的类库文件都包含进来了。

运行exerb hello_wx.exy,这时候生成的hello_wx.exe是可以执行的,问题是打开文件的同时会打开一个控制台窗口,要解决这个问题,就得修改hello_wx.exy文件,把cui改成gui。

  1. general:
  2.   startup: hello_wx.rb
  3.   core: gui #cui
  4.   kcode: none

再次运行exerb hello_wx.exy,生成一个红宝石图标的exe文件,OK!

另外,exy文件中还可以设置图标和版本信息。不再赘述。配置属性如下:

  1. resource:
  2. icon:
  3. - width : 16
  4. height: 16
  5. color : 4
  6. file : your_ico.ico
  7. - width : 32
  8. height: 32
  9. color : 4
  10. file : your_ico.ico
  11. version:
  12. file_version_number : 1.2.3.4
  13. product_version_number: 5.6.7.8
  14. comments : Comments Field
  15. company_name : Company Name Field
  16. legal_copyright : Legal Copyright Field
  17. legal_trademarks : Legal Trademarks Field
  18. file_version : File Version Field
  19. product_version : Product Version Field
  20. product_name : Product Name Field
  21. file_description : File Description Field
  22. internal_name : Internal Name Field
  23. original_filename : Original Filename Field
  24. private_build : Private Build Field
  25. special_build : Special Build Field
 类似资料: