JRoR: How to detect deployment in a WAR file programmatically?

I need to modify a plugin’s asset installation routines to handle
deployment in a WAR file, where there is no “public” directory.

So I’m looking for a programmatic way to key on the fact that I’ve
deployed via WAR file into a container? I’m thinking maybe I can detect
the absence of the “public” directory under RAILS_ROOT? Maybe an env.
var. set in web.xml? Another way?

Also, note that a standalone JRuby run of the app would have a public
directory (as normal) so using RUBY_PLATFORM =~ /java/ is not enough.

Thanks,
Wes


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

You could use Rails.public_path for this. I have no idea in which
version of
Rails was this introduced, but I think there’s also an alternative in
the
PUBLIC_ROOT constant. This will be also set if you use a recent version
of
warbler, and these will point to your real public direcotry.

LacKac

László’s solution is, much likely, the best one but I have another
suggestion that might be good if you are using Rails 1.2.x, for
instance: by
default, JRuby-Rack initializes a constant named PUBLIC_ROOT and you
could
just check it’s existence in config.rb. Here’s the code:

PUBLIC_ROOT = “#{RAILS_ROOT}/public” if !defined? PUBLIC_ROOT
ENV[‘PUBLIC_ROOT’] = PUBLIC_ROOT

I put the value of that constant in an environment variable just for
convenience. And those lines make development and deployment flexible -
your
assets will be installed in the default public root, no matter what
(.WAR or
not, JRuby or MRI, etc.). But, again, stick to László’s solution if you
are
using Rails 2.x+. :slight_smile:

[]'s, Renato.