[JRuby][JRubyFX] Ubuntu16.04でJRubyFXを動かす

手順としては次の通り。

  1. Java8を入れる
  2. rbenvを入れる
  3. jruby-1.7.26を入れる
  4. jrubyfxを入れる
  5. サンプルを動かす

まず、Javaを入れる。

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

次に、rbenvを入れる。

$ sudo apt-get install git build-essential libssl-dev
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

~/.profile の最後行あたりに次を記述。

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

つぎに、rbenvによりJRubyをインストールする。
ここでは、jruby-1.7.26を入れる。jruby-9kでもよいがアプリを動かしたときwarningが出るので、1.7系にしておく。

$ rbenv install --list
$ rbenv install jruby-1.7.26
$ rbenv global jruby-1.7.26


次に、jrubyfxを入れる。

$ jruby -S gem install jrubyfx


これで、準備が完了。
サンプルプログラムを動かしてみる。

require 'jrubyfx'

class Hello < JRubyFX::Application
  def start(stage)
    with(stage,title: "sample",width: 200,height: 100) do
      layout_scene do
        vbox do
          label("hello", id:"view")
        end
      end
      show
    end 
  end 
end

Hello.launch
$ jruby hello.rb