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()
metho开发者_Python百科ds, 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.
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.
精彩评论