How do I programmatically obtain the version in JBoss AS 5.1?

后端 未结 2 1446
走了就别回头了
走了就别回头了 2020-12-21 09:46

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

JBossAS 4.2 had org.jboss.Version, with getMajor()

2条回答
  •  星月不相逢
    2020-12-21 10:18

    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.

提交回复
热议问题