Require Gem libraries issue.

  9 posts   Feedicon  
Replies: 8 - Last Post: December 21, 2009 16:02
by: sundbp
showing 1 - 9 of 9
 
Posted: December 18, 2009 04:04 by chtrinh
I created a the 'hello world' app. Works fine. No bugs, no issues.
When i try to add a gem to the program with a simple
require 'rubygem'
require 'gem_name'
I get an application error. I followed the guide on the wiki, unpacking the gem and adding it appropriate code to manifest.rb.

The odd thing is that it looking for 'date', which is a jruby code file but it isn't find it.
BTW, i'm using the spreadsheet gem and it works fine in a console.


OUTPUT:
run:
Did not find configuration file 'run_configuration', using defaults.
inspecting args
Error in application
Java::OrgJrubyExceptions::RaiseException - org.jruby.exceptions.RaiseException: no such file to load -- date
/Users/chtrinh/NetBeansProjects/facebook/lib/ruby/spreadsheet/lib/spreadsheet/excel/internals.rb:1:in `require': no such file to load -- date (LoadError)
from /Users/chtrinh/NetBeansProjects/facebook/lib/ruby/spreadsheet/lib/spreadsheet/excel/internals.rb:1
from /Users/chtrinh/NetBeansProjects/facebook/lib/ruby/spreadsheet/lib/spreadsheet/excel/internals.rb:1:in `require'
from /Users/chtrinh/NetBeansProjects/facebook/lib/ruby/spreadsheet/lib/spreadsheet/excel/writer/workbook.rb:1
from /Users/chtrinh/NetBeansProjects/facebook/lib/ruby/spreadsheet/lib/spreadsheet/excel/writer/workbook.rb:1:in `require'
from /Users/chtrinh/NetBeansProjects/facebook/lib/ruby/spreadsheet/lib/spreadsheet/excel/writer.rb:1
from /Users/chtrinh/NetBeansProjects/facebook/lib/ruby/spreadsheet/lib/spreadsheet/excel/writer.rb:3:in `require'
from /Users/chtrinh/NetBeansProjects/facebook/lib/ruby/spreadsheet/lib/spreadsheet/excel/workbook.rb:3
from /Users/chtrinh/NetBeansProjects/facebook/lib/ruby/spreadsheet/lib/spreadsheet/excel/workbook.rb:27:in `require'
... 10 levels...
from /Users/chtrinh/NetBeansProjects/facebook/src/main.rb:51
from /Users/chtrinh/NetBeansProjects/facebook/src/main.rb:1:in `require'
from <script>:1
 
Posted: December 18, 2009 04:11 by chtrinh
Actually, I can't even do
require 'date'
I think there might be something wrong with how my system or netbeans is configure. Or maybe I'm just not getting this monkey business.

Advice and help wanted.
 
Posted: December 18, 2009 18:51 by Logan Barnett

A recent change to how JRuby handles stdlib broken this, and I've failed to release a patch to Monkeybars on time.

You can correct this by removing the $LOAD_PATH.clear in src/manifest.rb

 
Posted: December 19, 2009 05:29 by chtrinh
Thank you Logan. It worked.
 
Posted: December 18, 2009 12:10 by sundbp
Speaking about gems and monkeybars I have successfully started to use the new bundler for my gem management.

I was going to propose that perhaps this is a good route for monkeybars to go with respect to gems?

bundler is a way of defining your dependencies and have them downloaded and installed in a "vendor" type way so you can work with stable versions. It's what Rails3 will move to. here is a link:
http://yehudakatz.com/2009/11/03/using-the-new-gem-bundler-today/

There are two snafu's:

- i need to not compile ruby files since otherwise the paths gets messed up, i.e. gem-1.0.0 --> gem_minus_1_dot_0_dot_0
it compiles the files fine (all the activerecord/rails stuff as well as far as i can tell. the wiki says otherwise at the moment

- When bundling together my app into an osx app or windows exe I need to patch the generated bundler file I think this is because of a jruby bug with relationship to paths when in a jar-file though. What I need to do is:
change: @gemfile = "#{dir}/../Gemfile"
to: @gemfile = dir.gsub(/bundler_gems/, "") + "Gemfile"
I've sent an email to the jruby list about this. In the meantime I created a rake task to do this temporarily when I bundle the app.

Then in my manifest.rb file all I do is:
require 'bundler_gems/environment.rb' # add dependenceies to load paths
Bundler.require_env :optional_environment # actually require the files

voila, I have the correct load path and everything works fine. have the benfits of not having to manually unpack and rename all my gems and working with a standard framework (bundler) that since becoming part of rails is sure to get lots of users and support.

So, I have a question:

Is there any way of making the compilation step not change the paths as described above? I'm not a java dude so I'm not sure if it's a java class loader issue or something else.
 
Posted: December 18, 2009 18:57 by Logan Barnett

Re: Compiling The JRuby team may have resolved the issues regarding compilation with dashes. Feel free to update the wiki if you feel the issue is fixed!

Re: Paths

To keep stuff organized, we tossed everything into src. When you compile your app, typically everything is compiled with src treated as a base dir. This does cause us some issues, and I'm open to suggestions/patches that could get rid of this quirk.

Have you tried your bundler additions from a jar? jruby -S rake rawr:jar && cd package/jar && java -jar ChangeMe.jar

 
Posted: December 20, 2009 20:29 by sundbp
I wont touch the wiki just yet - since compiling changes the names (the - and . to _minus_ and _dot_) I'm not actually using the compiled classes yet. I can just say that there are no compilation errors, but not if the generated .class files are any good since I don't want to rewire all the paths by hand.

What I did was this:
- add a Gemfile in lib/ruby
- make bundler use lib/ruby/bundler_gems as it's directory
- use bundler to download gems etc.
- add the two lines referenced in last msg to my manifest.rb to make all the bundler gems available in load path

If running from filesystem and not compiling it just works. If running from jar it works once I make that small patch to the generated lib/ruby/bundler_gems/environment.rb (given in my last msg). I still haven't seen any response on the jruby mailing list of that's a jruby bug or not (I believe it is). Once I make that patch it works.

If I try to use compiled classes it doesn't work since the paths of the bundler gems get mangled (the - and .) and the resulting .class files can't be found. If there is a way of avoiding the compilation step doing anything but making .rb files to .class files (leaving all other names in paths unchanged) I'd like to try it so that I don't have to have .rb files in my jar.

 
Posted: December 21, 2009 14:37 by Logan Barnett

Sorry I don't have the specifics, but if you pull down the Rawr souce and check out the jarring/ruby compiling process, you'll see that we reach into JRuby internals and use it to determine the munged class name that pops out of jrubyc. You might be able to utilize that.

 
Posted: December 21, 2009 16:02 by sundbp
It'd have to be something patching some files before they get put into jar, because the "normal" paths get autogenerated by the bundler (into environment.rb) and are read from a file. So they are "set in stone" at the time you bundle the gems and would need to be overwritten when we create a jar.

That's obviously possible to do, just a rake task. Will see if I get time to look into the name-mangling.
showing 1 - 9 of 9
Replies: 8 - Last Post: December 21, 2009 16:02
by: sundbp
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close