I confess to not having done much with Rawr for perhaps close to a year.
I was heads-down on a Web project with little time for other things,
for almost two years.
At some a year or so ago I did check so older Monkeybars apps, which
lead to some updates (I think) of Monkeybars and Rawr. In any event,
code seemed to work.
Recently there's been some renewed interest in Rawr (and Monkeybars) and
people have reported that even simple code does not work.
Basically, trying to assemble a bare-bones app gives a "File not found"
error.
I tried this myself and sure enough stuff is broken.
I started looking into it. Rawr works by providing a Main class as an
executable entry point for a jar of files. It figures out the name of
the main Ruby file (typically main.rb, but configurable) and does a
script eval to require that file, which should in turn handle running
the actual app.
This main file is generally in the "src/" folder, and this gets
correctly packaged up in the jar created by Rawr, but $LOAD_PATH knows
nothing about this. In fact, $LOAD_PATH is almost empty, save for some
main folders that are part of the JRuby jar.
The code for Main.java hasn't changed in some time, so this is either
something from JRuby 1.6.x or Java itself, but I believe it's a change
in how JRuby is managing jar contents and $LOAD_PATH.
If something knows more or something to the contrary please speak up.
I've been searching for information that explains how JRuby handles the
load path when you require a jar but have not found anything recent to
help clarify things.
In the meantime I started a local branch to explore a fix and have code
that does some additional parsing of build_configuration.rb to add the
contents of "source_dirs" to $LOAD_PATH. (Typically this is just "src/".)
That works, and should be sufficient, since if any other locations need
to be added to $LOAD_PATH that main ruby file can do that.
If this is *not* sufficient we'll see what else we need.
If anyone thinks it's hacky or something, please speak up (with some
explanation and, ideally, an alternative if possible).
I will push this code to the Github repo tonight or tomorrow morning and
we can see how well it works for everyone.
Meanwhile, in my explorations, I learned that JRuby allows you specify a
Ruby file to use as the main class file for an executable jar:
https://github.com/jruby/jruby/wiki/StandaloneJarsAndClasses
From the looks of this I think that Main.java can be tossed if Rawr
assumes that the main Ruby file is jar-bootstrap.rb
We can replace the Rawr-generated Main.java with a generated
jar-bootstrap.rb that simply hands off to whatever
build_configuration.rb says is the main Ruby file. jar-bootstrap.rb may
have to do $OAD_PATH prep as well.
I've not written any code to even begin to try this out.
Finally, after some E-mails and some pondering I've decided to drop
Pivotal Tracker in favor of Github Issues for bug reports and such.
James Britt
https://github.com/rawr/rawr/tree/load-path-fix
If folks care to try it and see what they can break, please do.
James
I just tried this branch and it didn't work for me.
Here's a gist of my console output so you can see what I did after installing a new gem that I built from the branch.
https://gist.github.com/1316661
If anyone would care to reproduce and debug, I have tar'ed up my "test" directory. There's a single Ruby file foo.rb in the src directory. I can't seem to get this simple example functioning. :(
JRuby 1.6.3 at the moment... planning an upgrade to 1.6.5 next week.
http://dl.dropbox.com/u/44434337/test.tgz
cr
How did you create this project? There's no Main.java file in that tgz
archive.
This is usually created when you use rawr to initialize a project:
$ rawr install <project-path-or-current-dir>
James
The build configuration file had a new "main" file (foo) named as the main.
cr
Ah.
There are two main files. There's a Main.java that must exist in order
for the jar to be executable, and a main (or primary) Ruby file that is
invoked by Main.java.
The main ruby file can be called anything; the file name is read from
build_configuration.rb and dynamically invoked in Main.java.
When you run `rawr install` on a project folder it creates this
Main.java file as well as some additional folders. The main ruby file
generally goes in the src/ subdirectory of the project. (This is
configurable to some extent in build_configuration.rb.)
James