天天看點

開發了一個 java_side 插件

花了點時間把以前的一個內建spring的rails插件重寫了一下,技術含量沒有,但是能提供友善,主要是考慮了mvn和spring的內建使用,為jruby項目規範化開發提供幫助

https://github.com/fsword/java_side

下面是我寫的README:

JavaSide
========

為jruby on rails項目添加傳統java開發相關的支援

 - maven支援: 對rails項目中使用的第三方jar包,使用maven進行管理
 - spring支援: 對spring進行支援,在rails中使用已有的java服務

Installation
=============

rails plugin install git://github.com/fsword/java_side.git


Springframework Support
=======================

- 添加spring支援

1.修改 config/application.rb 檔案, 加入配置内容如下:

  class Application < Rails::Application
    ...
    config.spring = true
    ...
  end

2.檢查 java/pom.xml 檔案,確定springframework的相關依賴已經被添加(預設的pom.xml檔案本身就有).
3.運作打包任務:rake java_side:jars

- 使用

你可以直接在你的模型代碼中使用 get_bean ,如下:

class User < ActiveRecord::Base
  def doSth
    get_bean('your_bean_id').invokeTheService
    ...
  end
end

如果需要在代碼的其它位置使用,可以 include JavaSide::Spring,例如:

  Loading development environment (Rails 3.0.6)
  jruby-1.5.6 :001 > include JavaSide::Spring
   => Object
  jruby-1.5.6 :002 > x = get_bean 'sample'
   => #<Java::JavaUtil::ArrayList:0x496d864e>
  jruby-1.5.6 :003 > x.length
   => 3

Copyright (c) 2010 fsword, released under the MIT license