getting a "hello world" project to work

26 views
Skip to first unread message

cremes

unread,
Oct 24, 2011, 10:54:19 AM10/24/11
to rawr-lib
I am trying to get a simple 1 file "hello world" style program
packaged via rawr. So far, no luck. :(

Here is what I have done.

1. Created src/foo.rb


hash = {:a => 1, :b => 2}

puts "outputting hash"
p hash

sleep 5


2. Modified build_configuration.rb

https://gist.github.com/1309222

3. Typed "rake rawr:jar"


cremes$ rake rawr:jar
Loaded /Users/cremes/.rvm/gems/jruby-1.6.3/gems/rawr-1.6.0/lib/rawr/
core_ext.rb
Compile src/foo.rb into package/classes/ruby/foo.class
compile_dirs has src_dirs = ["src", "lib/ruby"]
glob_ruby_files has directory 'src' glob ["src/foo.rb"]
files for src: 1
glob_ruby_files has directory 'lib/ruby' glob []
files for lib/ruby: 0
ruby_globs.each has glob_data = #<OpenStruct files=["foo.rb"],
directory="src">
Go compile ["src/foo.rb"]
ruby_globs.each has glob_data = #<OpenStruct files=[],
directory="lib/ruby">


4. Tried to run it with "java -jar package/jar/test.tar"


cremes$ java -jar package/jar/test.jar
Exception in thread "main" org.jruby.exceptions.RaiseException:
(LoadError) no such file to load -- foo
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1038)
at #<Class:0x1239cd5f5>.(root)(<script>:1)



What am I doing wrong?

cr

James Britt

unread,
Oct 24, 2011, 11:35:29 AM10/24/11
to rawr...@googlegroups.com
cremes wrote:
> I am trying to get a simple 1 file "hello world" style program
> packaged via rawr. So far, no luck. :(
> ...
> What am I doing wrong?
>


Nothing, probably.

I and others have also run into the "no such file to load" exception.

I've done some work to fix this by adjusting the value of $LOAD_PATH by
parsing values out of build_configuration.rb for src and lib folders,
and this has worked for trivial examples. I have not tested it for
anything complex (though, offhand, I don't see why it wouldn't).

I will try to push something in the next few days so at least people can
try the current repo code to see if it works for them.


James

James Britt

unread,
Oct 24, 2011, 1:33:38 PM10/24/11
to rawr...@googlegroups.com
Chuck Remes wrote:

> On Oct 24, 2011, at 10:35 AM, James Britt wrote:
>
>> cremes wrote:
>>> I am trying to get a simple 1 file "hello world" style program
>>> packaged via rawr. So far, no luck. :(
>>> ... What am I doing wrong?
>> =20
>> =20
>> Nothing, probably.
>> =20

>> I and others have also run into the "no such file to load" exception.
>> =20
>> I've done some work to fix this by adjusting the value of $LOAD_PATH by p=
> arsing values out of build_configuration.rb for src and lib folders, and th=
> is has worked for trivial examples. I have not tested it for anything comp=

> lex (though, offhand, I don't see why it wouldn't).
>> =20
>> I will try to push something in the next few days so at least people can =

> try the current repo code to see if it works for them.
>
> That's unusual. I'm using JRuby 1.6.3, so maybe the 1.6x releases are a bit=
> less compatible with rawr than the 1.5x series?

Path handling appears to have changed.


>
> Do you (or any lurkers on the list) have a small example that *does work* u=
> nder recent JRuby releases? I'd like one even if I have to do some local pa=
> tching or messing around to get it to work. I have a deployment coming up w=
> ithin the next 2 weeks that could benefit from a rawr-like bundling. My end=
> users aren't exactly computer geniuses so I was hoping to provide them wit=
> h double-clickable EXEs. :)
>


Here's a hack you can do in Main.java

Prior to the line that actuall tries to require you main Ruby file, add
this:


runtime.evalScriptlet( "$: << 'src/'" );

This assumes your main.rb or foo.rb or whatever is the entry point for
your app is in src/


Something like this

runtime.evalScriptlet( "$: << 'src/'" );
runtime.evalScriptlet("require '" + mainRubyFile + "'");

BTW, this page suggests that Main.java can be done away with:

http://www.jruby.org/apidocs/org/jruby/JarBootstrapMain.html

but I've not tried anything yet.

James

Chuck Remes

unread,
Oct 24, 2011, 11:43:13 AM10/24/11
to rawr...@googlegroups.com
On Oct 24, 2011, at 10:35 AM, James Britt wrote:

That's unusual. I'm using JRuby 1.6.3, so maybe the 1.6x releases are a bit less compatible with rawr than the 1.5x series?

Do you (or any lurkers on the list) have a small example that *does work* under recent JRuby releases? I'd like one even if I have to do some local patching or messing around to get it to work. I have a deployment coming up within the next 2 weeks that could benefit from a rawr-like bundling. My end users aren't exactly computer geniuses so I was hoping to provide them with double-clickable EXEs. :)

cr

Chuck Remes

unread,
Oct 24, 2011, 1:47:26 PM10/24/11
to rawr...@googlegroups.com

On Oct 24, 2011, at 12:33 PM, James Britt wrote:

>
> Here's a hack you can do in Main.java
>
> Prior to the line that actuall tries to require you main Ruby file, add this:
>
>
> runtime.evalScriptlet( "$: << 'src/'" );
>
> This assumes your main.rb or foo.rb or whatever is the entry point for your app is in src/

Okay, this worked. I was able to regenerate the jar and run it as "java -jar /path/to/jar" successfully. Thank you for the fix/hack!

I will take a look at patching rawr so that the *.java file it produces has the right LOAD_PATH set so we can avoid this manual hack. I'll send a pull request if I get it working.

cr

Chuck Remes

unread,
Oct 24, 2011, 3:10:27 PM10/24/11
to rawr...@googlegroups.com

I've spent a few hours looking at how to add in the ability for Creator#create_java_main_file to add the ruby source directories to the LOAD_PATH, but I haven't had any luck. It looks like I should just be able to modify rawr_main.rb to pass +current_options+ to the call to ::Rawr::Create.create_java_main_file() but I can't get a spec working or that idea working. :(

I'll use the hack for now.

cr

James Britt

unread,
Oct 24, 2011, 3:52:23 PM10/24/11
to rawr...@googlegroups.com
Apologies for top-posting; I'm replying from my phone.

I have code that reads values from build_configuration.rb and dynamically primes the load path. What I posted was an excerpt to allow a cheap hack, but it's not how the proper code works.

I will be pushing that today or tomorrow; I'm traveling at the moment.


Chuck Remes <cremes....@mac.com> wrote:

>--
>You received this message because you are subscribed to the Google Groups "rawr-lib" group.
>To post to this group, send email to rawr...@googlegroups.com.
>To unsubscribe from this group, send email to rawr-lib+u...@googlegroups.com.
>For more options, visit this group at http://groups.google.com/group/rawr-lib?hl=en.
>

Reply all
Reply to author
Forward
0 new messages