Question

I'm trying to find the best way to grammatically determine if my program is running on Jboss 5 or Jboss 7 (eap-6.1). The ways I've been finding so far are jboss 5 or jboss 7 specific, which doesn't work because the code has to work in both. Tried both solutions from here: How do I programmatically obtain the version in JBoss AS 5.1? and they didn't work. One complained about org.jboss.Main not existing in jboss 7, the other complained aobut not finidng "jmx/rmi/RMIAdaptor".

The only way I can see is to do Class.forName to look for "org.jboss.Version" (should be found if jboss 5) and if that fails, do Class.forName "org.jboss.util.xml.catalog.Version" (jboss 7). But that seems like a terrible idea.

The reason I need to know if the war is running on jboss 5 or 7 is because there are some custom files that are located in different places in both. So it's like "if jboss 5, execute this piece of code, if jboss 7 execute the other.

Was it helpful?

Solution

Ok i just saw what the problem is.

I would suggest you to think about design issues/refactoring of your software.

If you want to provide your software within different environments, seperate your logic from technology dependencies.

Build facedes and interfaces to meet environmental requironments.

In my oppionen thats much better as to think we must support all integration platforms and support all there versions. This is completely impossible.

So decouple your business logic and offer specific interfaces. These interfaces (adapters) are much simplier to implement and to maintain.

Hope it helps.


UPDATE DUE TO COMMENT.


I think a solution is for servers 4 to 6 is to use the MBean Server of JBoss to lookup the registered web application which is associated to the deployed WarFile.

I suggest first to lookup the registered MBean of the web application manually using the JBoss jmx-console. The name of the WebApplication should be found under the capital "web" or "web-deployment" within the jmx-console.

If you found that name you can implement an own jmx based lookup mechanism to check for that name.

Here is an Tutorial: pretty old but i think it gives you an idea how to do. There must be more tutorials for this problem:

http://www.theserverside.com/news/1364648/Using-JMX-to-Manage-Web-Applications

Within JBoss 7 i just can give you the hint that its architecture is based on OSGI. So to lookup for other services you should have a look to this mechanism.

In any case you don't have direct access to the file system and the deployment directory from an application which is deployed within a JEE container, except of using the mechanisms provided by the container. JNDI Lookup, JMX ManagedBean mechanism, Java Connector Archicture (JCA) (makes no sense in your case)

OTHER TIPS

It's not an answer just an suggestions since the implementations are completely different

One way could be to use the "interceptors" which are executed during bootstrap and before any ejb invocation and there you have access to the invocation context in other words ejb container.

I can't give you any example but this would be an access point to start.

Another accesspoint is to check for system wide JMX Beans by looking through the Adminstratore console of the JBoss Server. You can inject JMX Bean state into your application through the Context Mechansim. Take a look from Version 4 to 6 at the JMX Managed Bean mechanism. The JMX Achitecture is the main concept of JBoss 3 to 6, so at this point you can influence and maintain the JBoss behaviour.

Aditionally i think you have differences from 4 to 6.x version and 7.0 because since 7 it's a completely new architecture. Since 7.0 the JMX architecture doens't exists anymore.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top