Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails server or console wont start #3753

Closed
swapab opened this issue Mar 22, 2016 · 6 comments
Closed

rails server or console wont start #3753

swapab opened this issue Mar 22, 2016 · 6 comments

Comments

@swapab
Copy link

swapab commented Mar 22, 2016

Environment

  • JRuby version :
    jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 Java HotSpot(TM) 64-Bit Server VM 25.65-b01 on 1.8.0_65-b17 +jit [linux-amd64]

  • Java version
    ➜ trunk java -version
    java version "1.8.0_65"
    Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
    Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

  • Operating system and platform

    ➜ trunk uname -a
    Linux swapnil-Lenovo-Z50-70 4.2.0-27-generic fix [JRUBY-5765]: cext build fails if 10.4 sdk installed #32-Ubuntu SMP Fri Jan 22 04:49:08 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

    ➜ trunk lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description: Ubuntu 15.10
    Release: 15.10
    Codename: wily

Relevant info:

Expected Behavior

rails c should start a rails console

Actual Behavior

Exception : LoadError: load error: hpricot_scan -- java.lang.NoSuchMethodError: org.jruby.RubyClass.defineMethod(Ljava/lang/String;Lorg/jruby/runtime/callback/Callback;)V

➜  trunk rails c
/home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/prawn-core-0.8.4/lib/prawn/core.rb:34: warning: already initialized constant VERSION
LoadError: load error: hpricot_scan -- java.lang.NoSuchMethodError: org.jruby.RubyClass.defineMethod(Ljava/lang/String;Lorg/jruby/runtime/callback/Callback;)V
           require at org/jruby/RubyKernel.java:940
  block in require at /home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:251
   load_dependency at /home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:236
           require at /home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/activesupport-3.2.22.1/lib/active_support/dependencies.rb:251
             <top> at /home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/hpricot-0.8.6-java/lib/hpricot.rb:20
           require at org/jruby/RubyKernel.java:940
   block in (root) at /home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/bundler-1.11.2/lib/bundler/runtime.rb:1
              each at org/jruby/RubyArray.java:1560
  block in require at /home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/bundler-1.11.2/lib/bundler/runtime.rb:77
              each at org/jruby/RubyArray.java:1560
           require at /home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/bundler-1.11.2/lib/bundler/runtime.rb:72
           require at /home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/bundler-1.11.2/lib/bundler/runtime.rb:61
             <top> at /home/swapnil/.rvm/gems/jruby-9.0.0.0@JayApp/gems/bundler-1.11.2/lib/bundler.rb:99
           require at org/jruby/RubyKernel.java:940
             <top> at /home/swapnil/Rails/Lab/MA-JRuby/trunk/config/application.rb:15
           require at org/jruby/RubyKernel.java:940
             <top> at script/rails:6
@swapab
Copy link
Author

swapab commented Mar 24, 2016

hpricot was causing the above error. I removed hpricot from Gemfile.

  • Next error faced.
    NameError: uninitialized constant ActiveRecord::Base::Mysql2

I had monkey patched mysql2_connection.

Looks like Mysql2::Client will no more work since jdbc-mysql is used.

What would be the alternative for Mysql2::Client ?

@headius
Copy link
Member

headius commented Mar 24, 2016

What are you using Mysql2::Client for?

We do not have a Java version of the mysql gem yet.

@headius
Copy link
Member

headius commented Mar 24, 2016

It looks like you're just using Mysql2::Client to get some configuration parameters. Perhaps the mysql JDBC driver has an equivalent way to set these options?

@swapab
Copy link
Author

swapab commented Mar 24, 2016

  • I had an override done on mysql2_connection. Which says:
    Establishes a connection to the database that's used by all Active Record objects

But since mysql2_connection is deprecated it can be ignored 😄

What are you using Mysql2::Client for?

  • I have escaped the quotes in a string using Mysql2::Client.escape. Which actually should have been done in a more abstract rails way.
Solution:

Instead of Mysql2::Client.escape use `ActiveRecord::Base.connection.quote_string

Both should give same results.

jruby

jruby-9.0.5.0 :021 > ActiveRecord::Base.connection.quote_string("O'Malley")
 => "O\\'Malley"

cruby

2.2.1 :005 > Mysql2::Client.escape("O'Malley")
 => "O\\'Malley"

This is great! ❤️ JRuby

@swapab
Copy link
Author

swapab commented Mar 24, 2016

I still have this question though. Does this ActiveRecord MULTI_STATEMENTS with mysql2 even work? (Considering ActiveRecord::Base#mysql2_connection is not yet deprecated)

@headius
Copy link
Member

headius commented Mar 24, 2016

@swapnilabnave I found this SO post that describes a few ways to get multiple statement support when using JDBC: http://stackoverflow.com/questions/10797794/multiple-queries-executed-in-java-in-single-statement

In any case there's no JRuby bug here so I'm closing this.

@headius headius closed this as completed Mar 24, 2016
@headius headius added this to the Invalid or Duplicate milestone Mar 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants