tags:

views:

140

answers:

2

Does anyone know how to programmatically obtain the server version number under JBossAS 5.1?

JBossAS 4.2 had org.jboss.Version, with getMajor() and getMinor() methods, but this doesn't seem to exist in 5.1.

+2  A: 

There are several ways to get the Version Number. I thing the official way is using JMX as as described on their Website, but for this the appserver has to reachable. The MBean to ask is jboss.system:type=server. You can even use the external shell skript twiddle for this:

%JBOSS_HOME%\bin>twiddle get jboss.system:type=Server VersionNumber
VersionNumber=5.1.0.GA

And here is the Code-Snippet from their Website (remote jmx):

MBeanServerConnection server = (MBeanServerConnection)new InitialContext().lookup("jmx/rmi/RMIAdaptor");
ObjectName on = new ObjectName("jboss.system:type=Server");
Object ver = server.getAttribute(on, "VersionNumber");

The other variant is using the package information of the loaded classes. If you load a class, like org.jboss.Main you are able to get the implementation version as specefied in the JAR file spec. Here is a example:

    org.jboss.Main m=new Main();   //at least a jboss class loaded. not needed in the container
    Package p=Package.getPackage("org.jboss");
    System.out.println("Major=" + p.getImplementationVersion().split("\\.")[0]);
    System.out.println("Minor=" + p.getImplementationVersion().split("\\.")[1]);

UPDATE: added version number by package inspection.

dz
That's very close to what I need, but for legacy reasons, I really need the distinct major and minor version numbers, rather than a combined string.
skaffman
A: 

In the end I chose to decompile the Version class from JBoss 4.2 to see what it was doing, and see if the result could be retrofitted into JBoss 5. The end result was to load the resource /org/jboss/version.properties into a Properties object, and then read out the version.major and version.minor properties from that. Beats me why they couldn't just leave the Version class in there, but there you go.

skaffman