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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With