Call Java with JRuby


#1

Hi,

I am a problem for my project at University…
the using:

JRuby => 1.8.6
Rails => 2.3.2
Java => JDK 1.6 and MySql 5.06

The Call java in Jruby is correct:

  • configuration the file jar
    Open File Configuration/environment.rb

    Dir["#{RAILS_ROOT}/lib/**/*.jar"].each do |jarfile|
    require jarfile
    end

*** And i added in this file
require ‘rubygems’
gem ‘activerecord-jdbc-adapter’
require ‘jdbc_adapter’
include Java

*** in the controller implements the costruct Java
import “java.post.PostInformation”
import “java.post.PostManagement”
class Post
def attibute
@title = post_info.setTitle(" “)
@description = post_info.setDescription(” ")
end

def create
@post_info = PostInformation.new
@post_mgm = PostManagement.new
post_mgm.addPost(attribute)
end

In the model
class Post

#Question: define the methods for views, it’s a correct???

def title
@post_info = PostInformation.new
post_info.setTitle(" ")
end

View

New post

<% form_tag :controller => ‘posts’, :active => ‘create’ do %>

<%= label_tag :title %>
<%= text_field_tag :title %>

<%= label_tag :description %>
<%= text_area_tag :description %>

<%= submit_tag 'Create' %>

<% end %>

sorry for my English … :stuck_out_tongue:

Thanks
Daniel