Checking defined?(JRUBY_VERSION)
appears to be the most idiomatic way of determining whether you're running in jruby (c.f. How can I tell if I'm running from JRuby vs. Ruby?, various FOSS jruby projects). Is there a similar idiom for determining whether you're running in Tomcat?
Asked
Active
Viewed 155 times
1
3 Answers
2
In the absence of an existing clearly established idiom, I'm going to propose defined?($servlet_context)
. This would be defined in any servlet container, not just Tomcat in particular, but that may be preferable anyway.

Araxia
- 1,136
- 11
- 22
-
Regarding your answer and subsequent flag [here](http://stackoverflow.com/questions/8337804/is-there-a-way-to-debug-a-jruby-on-rails-application-running-on-a-tomcat-server/8483552#8483552), you just deleted it. It won't be visible to anyone but you, moderators and 10k users. That's as good as it gets; SO doesn't really delete any content unless there is something really wrong with it. – NullUserException Dec 13 '11 at 02:39
0
Maybe something like:
public boolean isTomcat() {
try {
Class.forName("org.apache.tomcat.InstanceManager");
return true;
} catch (ClassNotFoundException ex) {
return false;
}
}

Rob Di Marco
- 43,054
- 9
- 66
- 56
-
That doesn't look much like an idiom. I suspect there is something concise that would work both in jruby and in a vanilla ruby implementation. And probably something using the same "defined? SOME_CONSTANT" pattern. – Araxia Dec 10 '11 at 00:21
0
works in both mri and jruby
IN_TOMCAT = begin
require 'org/apache/tomcat/InstanceManager'
defined?(Java::org::apache::tomcat::InstanceManager)
rescue LoadError;end

ffoeg
- 2,336
- 1
- 14
- 13