Running rails from a Jar


#1

Hi,

We did a recent effort to run from a Jar. We used a patch to require

from Peter Chan, which made things a bit easier. While it goes much
further with less patching to rails, there are still three main issues
that are failing:

1) File.directory? fails inside jars - During Rails initialization,

this is frequently done “if File.directory?(dir)”, so the initialization
procedure has to be patched because of this
2) Directory globbing fails inside jars - There are several places
where dir globbing is used, such as launching initializers
3) LOADPATH doesn’t seem to be respected when running from a jar.
This is the worst problem of all, since it makes loading the frameworks
require a lot of patching.

I wrote this mainly for future reference, but if anyone has fixed

any of these issues, I’d be interested to know about it.

best regards,
Ricardo T.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#2

I also gave this a try last month but gave up. What I wanted do was to
have
only two jars: jruby-complete and gems and run my Rails application with
these.

I think the optimal solution would be to have the Java filesystem API
take
care of these issues. This way if Ruby in any point tried to access
something from a jar it would succeed transparently. If this is solvable
in
JRuby somehow I don’t know, but I think it could be.

LacKac

On Thu, Apr 2, 2009 at 1:09 PM, Ricardo T. <


#3

László Bácsi wrote:

I also gave this a try last month but gave up. What I wanted do was to
have only two jars: jruby-complete and gems and run my Rails application
with these.

I think the optimal solution would be to have the Java filesystem API
take care of these issues. This way if Ruby in any point tried to access
something from a jar it would succeed transparently. If this is solvable
in JRuby somehow I don’t know, but I think it could be.

We’ve discussed this, and you’re basically right: we need a “virtual
filesystem” that works from within jar files (really, works with just
about any URL) mimicking the Java APIs. We would then use that to back
Dir and File.

I think there may be a few projects out there that attempt this. Maybe
one of them would work? Some research is in order.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

#4

Ricardo,
Monkeybars apps are distributed as a jar-only package. We have
workarounds for all of these issues.

On Apr 2, 2009, at 4:09 AM, Ricardo T. wrote:

Hi,

We did a recent effort to run from a Jar. We used a patch to
require from Peter Chan, which made things a bit easier. While it
goes much further with less patching to rails, there are still three
main issues that are failing:

  1. File.directory? fails inside jars - During Rails
    initialization, this is frequently done “if File.directory?(dir)”,
    so the initialization procedure has to be patched because of this

http://jira.codehaus.org/browse/JRUBY-2289 reports exactly what you’re
saying.
Here’s a sample from the Monkeybars code to find directories in a glob:
Dir.glob(File.expand_path(File.dirname(FILE) + “/**/*”)).each do |
directory|

File.directory? is broken in current JRuby for dirs inside jars

http://jira.codehaus.org/browse/JRUBY-2289

$LOAD_PATH << directory unless directory =~ /.\w+$/
end

So it’s basically treating extensionless files as directories. It’s
not perfect but that’s the best workaround we have right now.

  1. Directory globbing fails inside jars - There are several places
    where dir globbing is used, such as launching initializers

http://jira.codehaus.org/browse/JRUBY-2518
A Ruby-based fix is sitting in there. It doesn’t work for all kinds of
globs, but it worked for our case.

  1. LOADPATH doesn’t seem to be respected when running from a jar.
    This is the worst problem of all, since it makes loading the
    frameworks require a lot of patching.

$LOAD_PATH is respected, but has a lot of quirks. For one, your jar is
essentially treated as a dir, so you need to step out of the jar if
you need something outside of it with another.
Jar paths have file:// in the front, and myjar.jar!/inside_jar_dir
somewhere after that. If you’re stepping outside a jar, you’ll need to
remove the file://. The same works for reaching inside a jar.

Also, if you have requireable files of the same name sitting next to
your jar (foo.rb and myapp.jar!/foo.rb), JRuby will typically load
foo.rb. I think this is a load path quirk (the dir ‘.’ is on the load
path). We’ve gotten around this by clearing the load path on app start
and then rebuilding it. This also kept us from having gems that were a
part of our system get loaded even if the app didn’t have them - which
would then fail when giving the app to some other machine without
those gems. We have some documentation on this here:
http://kenai.com/projects/monkeybars/pages/UseRubyGemsInYourApplication

I wrote this mainly for future reference, but if anyone has fixed
any of these issues, I’d be interested to know about it. best
regards,
Ricardo T.

Another bugs you might be interested in:
http://jira.codehaus.org/browse/JRUBY-3499 - URL encoding problems
with jar paths (such as encoding spaces, but not reading the encoding
properly).
The bug says 3499 (the line above) is unresolved, but I think it’s
fixed now.

Hope that helps!

Logan B.
removed_email_address@domain.invalid
http://www.logustus.com


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email