Does anyone know how to programmatically obtain the server version number under JBossAS 5.1?
JBossAS 4.2 had org.jboss.Version, with getMajor()
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.