views:

567

answers:

3

I'm trying to install the hpricot gem on my Windows machine using JRuby 1.4.0RC1. I'm trying to follow the advice to the related question (see -> http://stackoverflow.com/questions/726412/installing-hpricot-for-jruby/1323619#1323619).

Per the answer's advice I pulled the git head of hpricot and from it's dir ran:

jruby -S rake package_jruby
cd pkg
sudo jgem install ./hpricot-0.8.1-jruby.gem

But when I run this I get the following NoClassDefFoundError:

Exception in thread "main" java.lang.NoClassDefFoundError: org/jruby/Main
Caused by: java.lang.ClassNotFoundException: org.jruby.Main
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: org.jruby.Main.  Program will exit.

Apparently my JRUBY_HOME\lib\jruby.jar is getting lost.

running jruby -v works fine, so I'm confused where my class path is getting messed up.

A: 

I suspect sudo does not inherit your environment variables. So JRUBY_HOME is gone. Try to add it to jgem profile.

Vladimir Dyuzhev
how do you add JRUBY_HOME to the jgem profile? $JRUBY_HOME is echoed in my bash and Windows cmd sessions.
dr
Do 'sudo jgem set' and check if it has the variable. If not, go to ~jgem (that it jgem home), find .profile file, and add the variable there.
Vladimir Dyuzhev
Thanks so much for your suggestions. Not sure if I'm able to do what you suggest. JRuby is coming up in the gem environment (see below). When I check out the installation dir, I don't see any file representing a profile. Pls see my 'answer' below for more context.
dr
A: 

I'm on Windows. I'm not sure if JRuby 1.4 drops the 'j' prefix. jgem isn't recognized, but gem is. Regardless, when I gem environment I get:

C:\tmp\hpricot>gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.5
  - RUBY VERSION: 1.8.7 (2009-09-30 patchlevel 174) [java]
  - INSTALLATION DIRECTORY: C:/jruby-1.4.0RC1/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: C:/jruby-1.4.0RC1/bin/../bin/jruby.bat
  - EXECUTABLE DIRECTORY: C:/jruby-1.4.0RC1/bin/../bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-java-1.6
  - GEM PATHS:
     - C:/jruby-1.4.0RC1/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "install" => "--env-shebang"
     - "update" => "--env-shebang"
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/
dr
+1  A: 

It looks like your jruby install isn't complete. Did you grab the bin or src dist? Check if lib/jruby.jar exists, make sure bin/jruby is in the same jruby location as lib/jruby.jar, and test java -jar lib/jruby.jar -e "puts 'hello'" to see if it's functional.

Charles Oliver Nutter
I think you're on the right track! I used the 'JRuby 1.4.0RC1 Windows Executable' to install JRuby. When I attempt java -jar lib/jruby.jar -e "puts 'hello'", I get the message: "Unable to access jarfile lib/jruby.jar". Do I have to specify JRUBY_HOME in the CP for each java execution or is there a way (or should the installer accomplish this) that I can make JRUBY_HOME inclusion the default? Thanks for your help!
dr
You may want to try the RC2 installer; I think there were some issues with the RC1 installer or the bat files that originally ran JRuby. Now that it ships with a jruby.exe, it may work correctly for you. If not, please file a bug at http://jira.codehaus.org/browse/JRUBY
Charles Oliver Nutter