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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2009-02-27 05:52
(Received via mailing list)
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
D3ab365ec2c78d27e5a68e912848e85f?d=identicon&s=25 László Bácsi (Guest)
on 2009-02-27 09:38
(Received via mailing list)
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
03ebcbbface06500195e3d3fe4d69119?d=identicon&s=25 Renato Santos (Guest)
on 2009-02-27 14:56
(Received via mailing list)
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+.   :)

[]'s, Renato.
This topic is locked and can not be replied to.