Forum: Ruby on Rails Struggling with Jruby Rails + jdbc driver

Posted by Joseph Li (Guest)
on 2013-02-14 23:03
(Received via mailing list)
hi all,

I am having a hard time trying to find out what's wrong with my setup. 
It
used to work smoothly until I decided out of the blue to do a selfupdate
and upgrade outdated on MacPort, then things started going south very
quickily.

Since MacPort kinda broke, I pull it all out and re-install the ports I
have before, which went pretty smoothly. Then to my surprise any command 
I
issue like ruby, gem /bundle started giving me "execv failed: Permission
denied (13)" error. Not much luck googling that. So after couple hours, 
I
pulled the whole thing as well. Remove all rubies from RVM and then
re-installing them.

I got to a point where the ruby, gem, bundle functions without problem. 
Now
firing up my test project it can no longer connect to the derby database
anymore. I tried manually adding the jdbc-derby  in the gem file even
thought I know "activerecord-jdbcderby-adapter" should have that as
dependency. But it is still giving me class not found error. Suspecting 
I
might have screwed my current project setting somehow, I created a brand
new app and added the same derby active record adaptor and jdbc-derby 
gem
in the gem file. Unfortunately I am still having the same problem listed
later in this post.

Coming from the Java world, the classpath thing is pretty easy to follow
even with maven.  However I am totally scratching my head on how jruby &
rails finds and loads the java lib and I can't seem to find any clear 
info
on that. I can see the  Any pointers on how to solve my problem and 
might
be potential place where I should look shall be greatly appreciated!!!

I can see the jdbc-derby gem installed under my .rvm dir but have no 
idea
how it gets loaded at runtime in jruby and rails:
./gems/jruby-1.7.2/gems/jdbc-derby-10.8.3.0
./gems/jruby-1.7.2/gems/jdbc-derby-10.8.3.0/lib
./gems/jruby-1.7.2/gems/jdbc-derby-10.8.3.0/lib/derby-10.8.3.0.jar
./gems/jruby-1.7.2/gems/jdbc-derby-10.8.3.0/lib/jdbc
./gems/jruby-1.7.2/gems/jdbc-derby-10.8.3.0/lib/jdbc/derby.rb
./gems/jruby-1.7.2/gems/jdbc-derby-10.8.3.0/LICENSE.txt
./gems/jruby-1.7.2/gems/jdbc-derby-10.8.3.0/Rakefile
./gems/jruby-1.7.2/gems/jdbc-derby-10.8.3.0/README.md




Error I am getting:

hello01 $ rails console
Loading development environment (Rails 3.2.12)
irb(main):001:0> User.all
NameError: cannot load Java class org.apache.derby.jdbc.ClientDriver
from org/jruby/javasupport/JavaClass.java:1227:in `for_name'
from org/jruby/javasupport/JavaUtilities.java:34:in `get_proxy_class'
from
file:/Users/josephli/.rvm/rubies/jruby-1.7.2/lib/jruby.jar!/jruby/java/core_ext/object.rb:26:in
`java_import'
from org/jruby/RubyArray.java:2361:in `map'
from
file:/Users/josephli/.rvm/rubies/jruby-1.7.2/lib/jruby.jar!/jruby/java/core_ext/object.rb:22:in
`java_import'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/jdbc/driver.rb:24:in
`driver_class'
from org/jruby/RubyModule.java:2291:in `module_eval'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/jdbc/driver.rb:23:in
`driver_class'
from org/jruby/javasupport/JavaObject.java:272:in `synchronized'
from org/jruby/javasupport/JavaProxyMethods.java:90:in `synchronized'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/jdbc/driver.rb:20:in
`driver_class'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/jdbc/driver.rb:8:in
`initialize'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/jdbc/connection.rb:44:in
`configure_jdbc'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/jdbc/connection.rb:24:in
`configure_connection'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/jdbc/connection.rb:82:in
`initialize'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/jdbc/adapter.rb:31:in
`initialize'
... 20 levels...
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/relation.rb:160:in
`to_a'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/explain.rb:33:in
`logging_query_plan'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/relation.rb:159:in
`to_a'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/relation/finder_methods.rb:159:in
`all'
from org/jruby/RubyBasicObject.java:1659:in `__send__'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/querying.rb:5:in
`all'
from (irb):1:in `evaluate'
from org/jruby/RubyKernel.java:1066:in `eval'
from org/jruby/RubyKernel.java:1392:in `loop'
from org/jruby/RubyKernel.java:1174:in `catch'
from org/jruby/RubyKernel.java:1174:in `catch'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in
`start'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in
`start'
from
/Users/josephli/.rvm/gems/jruby-1.7.2/gems/railties-3.2.12/lib/rails/commands.rb:41:in
`(root)'
from org/jruby/RubyKernel.java:1027:in `require'
from script/rails:6:in `(root)'irb(main):002:0>


Any help would be appreciated,

Joseph
Posted by Joseph Li (Guest)
on 2013-02-14 23:42
(Received via mailing list)
Now this is cheating. I finally decided to add the derbyclient.jar from 
the
maven repo to my CLASSPATH env var in my bash profile. Which get things
going for now. However, I am still baffled at what made it all work 
before
I did the whole MacPort & RVM reinstall routine as my bash_profile 
hasn't
been touched for quite some time already. Which only means things was
working without adding anything to the CLASSPATH.

I said my work around is cheating since the whole Gem + bundle + Gemfile
should have made the rail app kinda self contained and shouldn't rely on
external setting like CLASSPATH? Please correct me if I am wrong.

Anybody have similar experience?

Thanks,
Joseph
Posted by Joseph Li (Guest)
on 2013-02-15 05:15
(Received via mailing list)
I give up. But found a better workaround and that might just actually be
what I have done in the first place to get it working.

Turns out the jdbc-derby gem doesn't have the derbyclient network driver
but only the embedded driver. Thus the class not found. I tried many 
things
and thinking some combinations of the gems that I added trying to get it
work corrupted something. But still no dice. I ended up cleaning out the
jruby again from RVM. And then go  on to manually removing the
corresponding gem directory (.rvm/gems).

One thing I encountered amid the removal and reinstall was getting the
following err when trying to run bundle command:
*     ......ruby_noexec_wrapper*:*7:in* `*require*': *no such file to
load.......*
*Solution was to set the default ruby again from rvm with the 
"--default"
option.*
*
*

*And finally the workaround is..... just stick the derbyclient driver in
the ".rvm/rubies/jruby-1.7.2/lib" directory and that loaded 
automatically
and I don't have problem with intellij anymore that way.*


*If anyone knows how to solve this more elegantly, please let me know. 
My
gut feeling tells me it might involve a new gem or something, which I 
don't
know how to make yet.*
*
*
*Joseph *
*
*
*
*
*
*
Posted by Jordon Bedwell (Guest)
on 2013-02-15 05:18
(Received via mailing list)
On 02/14/2013 10:13 PM, Joseph Li wrote:
> One thing I encountered amid the removal and reinstall was getting the following
> err when trying to run bundle command:
> /     ......ruby_noexec_wrapper/:/7:in/ `/require/': /no such file to 
load......./
> /Solution was to set the default ruby again from rvm with the "--default" 
option./

That sir, is caused by rubygems-bundler in @global.
Posted by Joseph Li (Guest)
on 2013-02-15 05:42
(Received via mailing list)
Thank you Jordon, for the extra info. I have not yet master enough
knowledge of how rvm works yet. I just know enough commands to monkey it
around til it works. :> Guess a visit to the rvm / bundler page will be
needed soon.

Thanks,
Joseph
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.