4

Our EJB3 application can run on top of Oracle AS or JBoss AS. Is there a way to find out type of AS during runtime?

tputkonen
  • 5,579
  • 16
  • 60
  • 88
  • Duplicate of http://stackoverflow.com/questions/1745836/determine-which-application-server-our-application-is-deployed-to and http://stackoverflow.com/questions/2117704/how-can-i-determine-the-j2ee-application-server-type-and-version – skaffman Feb 11 '10 at 14:24
  • Our application is not a web application – tputkonen Feb 11 '10 at 14:31
  • I didn't say it was. Neither of those duplicates is specific to webapps. – skaffman Feb 11 '10 at 14:34

2 Answers2

2

Another way is to check for an app-server specific value in System properties.

// EXAMPLE:
if (System.getProperty("catalina.base") != null) {
  // Using Tomcat
  ...
else if (System.getProperty("jboss.server.name") != null) {
  // Using JBoss
  ...
else if (System.getProperty("was.install.root") != null) {
  // Using WebSphere
  ...
paulsm4
  • 114,292
  • 17
  • 138
  • 190
1

You can check the concrete type of object at runtime using reflection, e.g. the EJBContext that is injected by the app. server.

ewernli
  • 38,045
  • 5
  • 92
  • 123
  • Thanks!! In jboss it returns: org.jboss.ejb3.stateless.StatelessSessionContextImpl – tputkonen Feb 11 '10 at 15:05
  • disadvantage may be that you need some `@EJB class Ejb { @Inject EJBContext ejbCtx; }` to make it work. so the system properties approach in our scenario seemed more fitting: https://stackoverflow.com/a/41528206/1915920 – Andreas Covidiot Apr 15 '21 at 11:57