gem和plugin 的不同

本文分享了使用JRuby将项目打包成WAR文件的经验,包括推荐使用gem而非plugin以避免兼容性问题,以及介绍warble complied war能直接将Ruby代码转换为Class文件,提升程序安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天把jruby项目打包成war,总结了点经验:

1.如果可以用gem别用 plugin,用plugin容易导致兼容性问题导致打包失败,下面的转帖就是gem和plugin的区别

2.warble complied war可以直接将打包的rb生成class,从而使程序有更好的加密

As a newbie to Rails, "Gem" and "Plugin" terminology was slightly confusing to me. Specifically I saw the terms being used interchangeably sometimes. This TOTD highlights the difference between Ruby Gem and Rails Plugin.

Ruby Gem and Plugin are both packaging systems - the main difference is the scope in which they are effective. The common differences are highlighted in the table below.

TopicRuby GemRails Plugin
DefinitionA Gem is a packaged Ruby application using the packaging system defined by RubyGems.A Rails plugin is a packaged Ruby application that extends the core Rails framework.
ExampleHas a name (e.g. rake) and a version (e.g. 0.4.16). Rails is also installed as a Gem.Has a name (e.g. Goldspike) and a version (e.g. 1.1.1).
ScopeInstalled in the Ruby or JRuby installation and is available to all applications run using that interpreter.Installed in a specific Rails app only.
Packaging SystemRails gem is installed in jruby-1.0//lib//ruby//gems//1.8//gems//rails-1.2.3 as:

<DIR>        bin
<DIR>        builtin
      68,465 CHANGELOG
<DIR>        configs
<DIR>        dispatches
<DIR>        doc
<DIR>        environments
307          fresh_rakefile
<DIR>        helpers
<DIR>        html
<DIR>        lib
       1,072 MIT-LICENSE
      11,969 Rakefile
       8,001 README

The lib directory contains all the gem source code.

Goldspike plugin is installed in vendor//plugins//rails-integration directory of the application as:

      7,089 build.xml
      1,141 LICENSE.txt
<DIR>       plugins
      6,675 pom.xml
      1,447 README
<DIR>       samples

plugins/goldspike directory consists of

         24 init.rb
         25 install.rb
<DIR>       lib
        549 Rakefile
        536 README
<DIR>       tasks
<DIR>       test

The lib directory contains all the plugin source code.

ManagementGems are managed on your computer using the gem command. You can install, remove and query gem packages using the gem command.Plugins can be installed using after creating a Rails application and then invoking the command

ruby script//plugin install [url or name of plugin]
Load Pathgem command adds the lib directory of your gem to the load path of Ruby.Rails adds the lib directory of plugin in your application's load path.
Specific Features 
  • Bundled Rake tasks that get automatically loaded into your Rakefile
  • An installation hook (install.rb)
  • An application initialization hook for the plugin to inject itself (init.rb)
  • ability to bundle additional generators (for the script/generate script)
Publish FormatA Gem may be published as Plugin, for example ActiveRecord-JDBC.A Plugin cannot be published as Gem.

Here are some useful entries (with numerous pointers on screencasts, blogs, tips & extensive feature sets) to get you started with JRuby:

Are there any other main differences that I missed ?

Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.

Technorati: totd rubyonrails rubygem railsplugin netbeans glassfish

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值