EzDevInfo.com

jruby

JRuby, an implementation of Ruby on the JVM Home — JRuby.org jruby is a high performance, stable, fully threaded java implementation of the ruby programming language.

JRuby on Rails vs. Ruby on Rails, what's difference?

I'm looking to try out JRuby and JRuby on Rails. I'm having trouble finding information on what's difference between JRuby on Rails and Ruby on Rails.

What's the differences I need to look out for?


Source: (StackOverflow)

How to run Ruby 2.0 with JRuby 1.7?

What is the best way to get JRuby to run in 2.0 mode?


Source: (StackOverflow)

Advertisements

Can I program for android using any JVM language?

Can I use other JVM languages besides Java (e.g. jruby, jython, clojure) to program for android, or is it java only?

There was a similar question asked over a year ago but I wasn't sure if there'd been any change since then.


Source: (StackOverflow)

Visit method not found in my rspec

My java web application is running on tomcat at http://localhost:8080/

Writing my first spec, home_spec:

require 'spec_helper'


describe "home" do

    it "should render the home page" do
       visit "/"

       page.should have_content("hello world")
    end

end

And running:

rspec

I get:

F

Failures:

  1) home should render the home page
     Failure/Error: visit "/"
     NoMethodError:
       undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x242870b7>
     # ./spec/home/home_spec.rb:7:in `(root)'

Finished in 0.012 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/home/home_spec.rb:6 # home should render the home page

Shouldn't this work because I have included capybara in the spec_helper?

How will it know to visit the correct url? what if my url is localhost:3030 or localhost:8080?

My gemfile:

source 'http://rubygems.org'

gem "activerecord"
gem "rspec"
gem "capybara"
gem "activerecord-jdbcmysql-adapter"

My spec_helper:

require 'capybara/rspec'

Source: (StackOverflow)

Groovy advantages over Jython or Jruby?

Why would I choose to use Groovy when I could use Jython or Jruby? Does the language provide any inherent advantages to make up for the fact that Jython and Jruby skills are applicable to their parent languages outside of the JVM?

Keep in mind that I purposely keeping this question generic, but if there are any advantages that exist in a particular domain, please don't hesitate to describe them.

EDIT
To clarify, If I write some code in Jruby, I can now, in some cases, move that code outside of the JVM if need be, or at the very least I have gained a better understanding of Ruby. Whereas Groovy skills are applicable only when using a language that just exists inside the JVM. Jython and Jruby have this built in advantage, what does Groovy have to make up for this disadvantage?

If Groovy doesn't have any advantages that you've found, and you would suggest just using Jython or Jruby, let me know.

Edit 2
Thanks everyone for all the answers, most of them make the same point, Groovy integrates slightly better with Java then Jython or Jruby.

Follow up
Using Netbeans 6.5 as my IDE I have found that Groovy to integrates better with Java projects then Jruby. I am not sure if lack of integration is a failing of Jruby or Netbeans. But after using it for alittle Groovy definitely seems to have a leg up.


Source: (StackOverflow)

OpenSSL::Cipher::CipherError with Rails4 on JRuby

Rails4 uses an encrypted cookie session store by default. When the app tries to encrypt a cookie the following error is raised: OpenSSL::Cipher::CipherError: Illegal key size: possibly you need to install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for your JRE (stacktrace: https://gist.github.com/8ba56b18060ae30e4d44).

As mentioned here this can be worked around by downgrading cryptography or installing JCE - the first being something I don't really want to do and the latter being impossible (afaik) on heroku.


Source: (StackOverflow)

What's the difference between Duby and Juby and why would I need either of them?

According to Charles Nutter, Duby is

a static-typed language with Ruby's syntax and Java's type system. Duby supports all Ruby's literals, uses local type inference (only argument types must be declared), and runs as fast as Java (because it produces nearly identical bytecode). But with the advent of invokedynamic, Duby needed a playmate.

1. What's invokedynamic and why does Duby "need a playmate"?

Juby, on the other hand, is

intended to be basically like Duby, in that it uses Java's types and Ruby's syntax. But it takes advantage of the new invokedynamic opcode to be 100% dynamic. Juby is a dynamic Duby, or perhaps a dynamic Java with Ruby syntax. It's not hard to comprehend.

Actually it is hard to comprehend.

2. Could someone elaborate a little bit more on what this distinction is about?

3. Why do we need (need!) another Ruby-related language? Or, rather, two more Ruby-related languages?


Source: (StackOverflow)

Undefined method `bytesize' for #

I'd like to store and update blogger labels to datastore in GAE. When I run that code, I get this error:

javax.servlet.ServletContext log: Application Error
/base/data/home/apps/yet-another-problem/1.334886515480009498/WEB-INF/gems/gems/sinatra-0.9.2/lib/sinatra/base.rb:45:in `each': undefined method `bytesize' for #<Hash:0x86684c> (NoMethodError)

The Code

class Labels
   class LabelData
    include Bumble
    ds :blog_element_labels
   end

  def update
    response = URLFetch.get($label_url)
    result = response.to_s
    result_headless = result.gsub("listLabels(",'')
    pure_result = result_headless.gsub(");",'')
    json_to_yaml = YAML::load(pure_result)['entry']['category']

    json_to_yaml.each do |label|
    @label = LabelData.find(:blog_element_labels => label['term'])
    @label = LabelData.create(:blog_element_labels => label['term']) if @label.nil?
    end
  end
end

and run by cron job does '/job'

get '/job' do
  @labels = Labels.new
  @labels.update
end

Where is the problem? Please teach me.

But when run cron job first time, label data was stored, even occur that error. Could not update data.


Source: (StackOverflow)

Create deployable JRuby JAR file?

I need to compile my JRuby application into a standalone JAR file. How can I do this?


Source: (StackOverflow)

How to profile JRuby code?

I'd like to profile my JRuby app. For MRI I always use ruby-prof, but I don't think this works on JRuby. I don't want to use a Java-profiler, because it won't give me the ruby line numbers.

Is there a jruby-prof?


Source: (StackOverflow)

Scan HTable rows for specific column value using HBase shell

I want to scan rows in a HTable from hbase shell where a column family (i.e., Tweet) has a particular value (i.e., user_id).

Now I want to find all rows where tweet:user_id has value test1 as this column has value 'test1'

column=tweet:user_id, timestamp=1339581201187, value=test1

Though I can scan table for a particular using,

scan 'tweetsTable',{COLUMNS => 'tweet:user_id'}

but I did not find any way to scan a row for a value.

Is it possible to do this via HBase Shell?

I checked this question as well.


Source: (StackOverflow)

JRuby Performance

I have a Rails 3.2.2 application that I am looking to run using JRuby 1.6.7 (1.9.2 mode).

I have a sample app running in MRI ruby 1.9.3 and a typical request is returning in ~40ms: Completed 200 OK in 36ms (Views: 27.5ms | ActiveRecord: 8.2ms)

Under JRuby using the same request is anywhere from 3 to 20 times slower depending on the page. For the same operation as above it takes ~180ms: Completed 200 OK in 180ms (Views: 153.0ms | ActiveRecord: 24.0ms)

Is this a normal performance difference? I have read that JRuby is roughly equal on speed with MRI. The results hold on my Mac and a Windows server (where unfortunately it will need to run). Packaging it up with Warbler running under Tomcat is just as slow.

The above times are from a basic rails app created for testing the JRuby. On the more complex app the times are even farther apart. On that app there is more ruby code being run on some pages. It seems that the more the page is ruby dependent the greater the performance difference I am observing. I have done no tuning of JRuby, since I don't know quite where to start.

So my questions are: is this normal? What can I do to tune JRuby?


Source: (StackOverflow)

JRuby on Rails: Adding a folder to the classpath

I'm trying to add an entire folder to the JRuby 1.5 classpath for my Rails app. The JRuby Wiki suggests the following: "... add the config directory to the JRuby classpath in config/environment.rb:"

$CLASSPATH << "file:///#{File.expand_path(File.join(RAILS_ROOT, 'config'))}/"

That doesn't seem to work for me. It doesn't matter whether I put that before, after or inside of the Rails::Initializer.run block. No matter what, I get:

/home/sean/src/sbruby/seo/config/environment.rb:45:NoMethodError: undefined method `<<' for nil:NilClass
/home/sean/apps/jruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/rails-2.3.7/lib/rails/backtrace_cleaner.rb:2:NameError: uninitialized constant ActiveSupport::BacktraceCleaner
/home/sean/apps/jruby/jruby-1.5.0/lib/ruby/gems/1.8/gems/rails-2.3.7/lib/console_with_helpers.rb:5:NameError: uninitialized constant ApplicationController

For example, I'm trying to add a folder under RAILS_ROOT called resources/foobar, so I added the following to environment.rb:

$CLASSPATH << "file:///#{File.expand_path(File.join(RAILS_ROOT, "resources", "foobar"))}/"

Same error.

What is the right way to add a folder to the JRuby classpath with Rails?


Source: (StackOverflow)

Faster RSpec with JRuby

I'm pretty new to the whole JRuby world. I'm using RSpec on a pretty big test suite. I'd like to be able to run the specs frequently but the JVM takes so long to startup it's becoming a real time drain.

Is there a way to keep the JVM running? or a way to get specs to run faster with JRuby?


Source: (StackOverflow)

Already initialized constant in jruby-openssl

When running my rails application on torquebox, I get a lot of

already initialized constant: ...

warnings that originate from gems/jruby-openssl-0.8.2/lib/shared/jruby-openssl.rb:16. Is this a security problem? Is there any way to get rid of these warnings?


Source: (StackOverflow)