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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Wes G. (Guest)
on 2009-02-27 06: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.


To unsubscribe from this list, please visit:
László Bácsi (Guest)
on 2009-02-27 10: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
PUBLIC_ROOT constant. This will be also set if you use a recent version
warbler, and these will point to your real public direcotry.

Renato Santos (Guest)
on 2009-02-27 15: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
just check it's existence in config.rb. Here's the code:

PUBLIC_ROOT = "#{RAILS_ROOT}/public" if !defined? PUBLIC_ROOT

I put the value of that constant in an environment variable just for
convenience. And those lines make development and deployment flexible -
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
using Rails 2.x+.   :)

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