0

How can I excecute command in java to find the version of the tomcat installed in java programming. I tried using command java -cp .catalina.jar org.apache.catalina.util.ServerInfo but I am unable to understand to give the path of the tomcat installed directory

        String line1;
          BufferedReader input1;
          Process p2 = Runtime.getRuntime().exec(new String[] {
                "cmd /c start cmd.exe /K java -cp catalina.jar 
                 org.apache.catalina.util.ServerInfo /s" });

          input1 = new BufferedReader(new 
          InputStreamReader(p2.getInputStream()));
          while ((line1 = input1.readLine()) != null) {
          System.out.println(line1);

        }
        input1.close();

I need to print version of the tomcat installed using commands in java

  • Possible duplicate of [How to get Tomcat version number in Java](https://stackoverflow.com/questions/27244947/how-to-get-tomcat-version-number-in-java?answertab=active#tab-top) – Sabesh Jan 22 '19 at 09:00

1 Answers1

0

You can use methods of class ServerInfo:

Simple utility module to make it easy to plug in the server identifier when integrating Tomcat.

As follow:

// Return the server built time for this version of Tomcat.    
System.out.println(ServerInfo.getServerBuilt());

// Return the server identification for this version of Tomcat.
System.out.println(ServerInfo.getServerInfo());

// Return the server's version number.
System.out.println(ServerInfo.getServerNumber());
Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56