问题描述:

I'm having problems getting rawr to build a jar file. I'm using JRuby 1.6.5.1 on OS X Lion.

Installation:

jruby --1.9 -S rawr install

In the src directory I create a simple hello_jruby.rb containing:

puts "Hello JRuby!"

The build_configuration.rb file has the following settings:

c.project_name = "hello_jruby"

c.executable_type = "console"

c.main_ruby_file = "hello_jruby"

Generate the jar file:

$ jruby --1.9 -S rake rawr:jar

mkdir -p package/classes/java

javac -target 1.6 -cp lib/java/jruby-complete.jar:src -sourcepath src -d package/classes/java src/org/monkeybars/rawr/Main.java

mkdir -p package/classes/ruby

Copying source file src/hello_jruby.rb to package/classes/ruby/hello_jruby.rb

cp src/hello_jruby.rb package/classes/ruby/hello_jruby.rb

mkdir -p package/classes/META-INF

mkdir -p package/jar

=== Creating jar file: package/jar/hello_jruby.jar

cp lib/java/jruby-complete.jar package/jar/lib/java/jruby-complete.jar

Neither execution of the jar file prints the output:

$ java -jar ./hello_jruby.jar

$ java -cp .:./lib/java/jruby-complete.jar -jar ./hello_jruby.jar

I'm totally confused as to why this doesn't work. I have tried on Windows, but the CLASSPATH separator used by rawr is a colon(:) instead of a semi-colon(;) so the rawr:jar doesn't work.

I must be missing something or don't fully understand how to use rawr.

Any ideas are welcome. Thanks for your time!

EDIT: Additional Attempts and Results

Installed the latest JRuby (not using RVM):

$ jruby --1.9 -v

jruby 1.6.7.2 (ruby-1.9.2-p312) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_33) [darwin-x86_64-java]

Java version:

$ java -version

java version "1.6.0_33"

Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)

Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)

Installed the latest rawr:

$ jruby --1.9 -S gem install rawr --source http://gems.neurogami.com

Fetching: rawr-1.6.3.gem (100%)

Successfully installed rawr-1.6.3

1 gem installed

One thing I noticed is that the rawr executable is placed in the Ruby 1.9.2 directory. Is this normal and expected?

$ which rawr

/Users/david/.rvm/gems/ruby-1.9.2-p290/bin/rawr

The following command fails now. I previously had installed JRuby using RVM. Prior to installing the latest JRuby I uninstalled the RVM JRuby.

$ jruby --1.9 -S rake -T

(in /Users/david/Dropbox/SourceCode/Ruby/RubySandbox/rawr_test)

rake aborted!

no such file to load -- ftools

(See full trace by running task with --trace)

However, running rake via ruby 1.9.2 works:

$ rake -T

Generated the jar using the following:

$ rake rawr:jar

Still getting no output or errors when generating the jar.

$ java -jar ./hello_jruby.jar

$

Running the script using JRuby is successful:

$ jruby --1.9 ./hello_jruby.rb

Hello JRuby!

The generated jar has the following files:

$ ls -R

META-INF java ruby

hello_jruby.rb org run_configuration

./META-INF:

MANIFEST.MF

./java:

./org:

monkeybars

./org/monkeybars:

rawr

./org/monkeybars/rawr:

Main.class

./ruby:

TEST01: Using system JRuby and avoiding RVM Ruby 1.9.2.

$ rvm use ruby-1.9.2

$ gem uninstall rawr

$ rvm system

$ jruby --1.9 -S gem install rawr --source http://gems.neurogami.com

$ which rawr

/Library/Frameworks/JRuby.framework/Versions/Current/bin/rawr

$ jruby --1.9 -S rawr install

$ jruby --1.9 -S rake rawr:jar

The rawr executable is now in a different location. However, still getting no output from the jar. I even tried all jruby commands without --1.9 with no difference. I'm going to give it a another shot on Windows too.

Next test is to pull the latest rawr source and run through the mentioned instructions.

Thanks again!

网友答案:

First: no, the gem probably shouldn't show up under your 1.9.2 install. RVM must think you're still using 1.9.2. Since your JRuby is outside of rvm, type rvm system to ignore all rvm-installed Rubys. You might want to uninstall rawr from 1.9.2 first.

(An aside: I just installed rawr under my 1.9.3 Ruby and it still worked fine. Weird.)

Following up on my comments: I've done some digging and it looks like the gem hosted at neurogami.com is still behind git HEAD. I got that same error about ftools using it. What I have done to get it working (on Ubuntu and Windows) is:

  1. gem install bones
  2. gem install rspec -v 1.3.0
  3. git clone https://github.com/rawr/rawr.git
  4. cd rawr
  5. rake gem:package
  6. gem install pkg/rawr-1.6.3.gem
  7. cd ..
  8. mkdir rawr-test-TEMP
  9. cd rawr-test-TEMP
  10. rawr install
  11. create hello_jruby.rb and add proper config options to build_configuration.rb (I also had to add c.target_jvm_version = 1.7 because rawr didn't pick up my Java 7 install)
  12. edit line 667 of lib/zip/zip.rb inside your rawr gem's directory -- add a closing parenthesis to the end. This is a bug in upstream rawr.
  13. rake rawr:jar
相关阅读:
Top