7 Replies Latest reply on Jun 14, 2016 6:27 PM by ctomc

    How to detect Wildfly version

    lindner

      Is it possible to detect wildfly's version via java in my application? Something like

       

      Class.forName("org.jboss.as.server.Main"); // laden forcieren
      Package p = Package.getPackage("org.jboss.as.server");

       

      jbossMajorVersion = Integer.parseInt(p.getImplementationVersion().split("\\.")[0]);

      jbossMinorVersion = Integer.parseInt(p.getImplementationVersion().split("\\.")[1]);


      as it was possible in JBoss 7?

        • 1. Re: How to detect Wildfly version
          ctomc

          That should probably still work.

           

          but that is not proper way of detecting it.

           

          you are looking for class org.jboss.as.version.Version that is part of module "org.jboss.as.version" which you should depend on if you want to access this.

           

          see https://github.com/wildfly/wildfly/blob/master/version/src/main/java/org/jboss/as/version/Version.java

           

          that is the same also in AS7.

          1 of 1 people found this helpful
          • 2. Re: How to detect Wildfly version
            lindner

            Thank you Tomaz,

             

            and for all readers with the same question: you will need module "org.jboss.as.standalone" too

            • 3. Re: How to detect Wildfly version
              ehugonnet

              Here is what you can do in a servlet :

              protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ...     ProductConfig config = new ProductConfig(ModuleLoader.forClassLoader(this.getClass().getClassLoader()), System.getProperty(ServerEnvironment.HOME_DIR, null), null);  ... }

              You also have to create a jboss-deployment-structure.xml file with dependencies on

              • org.jboss.as.version
              • org.jboss.as.server
              • org.jboss.modules

              Be careful as you are using internal API so they might break in the future.

              I've attached a simple war example.

              • 4. Re: How to detect Wildfly version
                rcd

                Indeed, the module org.jboss.as.version is marked as private, and recent versions of WildFly will log warnings if your deployment uses it. Fortunately, there is another way to obtain the version using JMX that requires no additional dependencies.

                 

                Use java.lang.management.ManagementFactory#getPlatformMBeanServer() to obtain a MBeanServer, then perform a lookup on object name "jboss.as:management-root=server", attribute "productVersion". This will return the WildFly Full version. There is another attribute (can't remember the name of it) that returns the WildFly Core version, if you're interested in that. Our code does this and it works great, currently running on WildFly 10.0.0.CR2.

                • 5. Re: How to detect Wildfly version
                  ehugonnet

                  JMX may not be there as it is an extension. You could connect using the controller-client API (or the cli or just a REST call) to the management API and the version is available there too.

                  • 6. Re: How to detect Wildfly version
                    a-i-ks

                    Is there a possibility to detect the WildFly version without starting the server? I need to detect the version as a prelaunch check before the server startup?

                    • 7. Re: How to detect Wildfly version
                      ctomc

                      Andre Iske wrote:

                       

                      Is there a possibility to detect the WildFly version without starting the server? I need to detect the version as a prelaunch check before the server startup?

                      Look into org.jboss.as.version module.

                      open the wildfly-version.jar and look at its manifest.