0

Some existing answers say to go to SOFTWARE\Apache Software Foundation\TomcatVERSION

But I cant find any tomcatVersion directory

I do have

SOFTWARE\Apache Software Foundation\Tomcat\9.0\Tomcat9

Inside this, there is a version attribute which tells that the tomcat version is 9

but the target folder location changes with version. If I have tomcat8, the target folder location is

SOFTWARE\Apache Software Foundation\Tomcat\8.0\Tomcat8

I need a fixed path that will tell me the existing tomcat version on my device. Thanks in advance.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • 1
    1) Tomcat can run from command line without any traces in the registry. 2) There's a limited number of versions available and the registry key might change any time in future - you might be best off to just enumerate the known versions (and decide if you're only caring for the Apache versions, or also the commercially supported ones, tomee, or other variations thereof) – Olaf Kock Jul 23 '21 at 15:22
  • The registry keys are only used by the [MSI Installer](https://github.com/apache/tomcat/blob/678c7a0aaa5de05b99ce3cf005fe79504fe683bc/res/tomcat.nsi#L353). Since it doesn't support upgrades, the real version of Tomcat will probably not be reflected in the registry. – Piotr P. Karwasz Jul 24 '21 at 11:21

2 Answers2

1

You can't. There is no path that will tell you the exact Apache Tomcat version installed. You have several options.

There is a version.[bat|sh] script in $CATALINA_HOME/bin that will report the exact Tomcat version along with OS and JVM info. This requires that the JAVA_HOME environment variable is correctly set.

If you look in the /META-INF/MANIFEST.MF file in $CATALINA_HOME/lib/catalina.jar you will find an Implementation-Version field that lists the exact version. Note that the specification JARs report the specification implementation version, not the Tomcat version so you can;t just pick any JAR.

You will also find version information at /org/apache/catalina/util/ServerInfo.properties in $CATALINA_HOME/lib/catalina.jar.

The full version information is also reported in the logs when Tomcat starts.

Mark Thomas
  • 16,339
  • 1
  • 39
  • 60
0

I am posting this to maybe inspire others.

I had a very dumb idea that just might work, calling the powershell and getting the tomcat version with a command, then reading the output so you can do what you want with it.

Please note this code is a jugaad!

using (Process process = new Process())
{
    process.StartInfo.FileName = "powershell.exe";
    process.StartInfo.Arguments = "(get-service Tomcat*).DisplayName";
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.Start();

    // Synchronously read the standard output of the spawned process.
    StreamReader reader = process.StandardOutput;
    string output = reader.ReadToEnd();

    process.WaitForExit();

    //do whatever you want with output (such as string manipulation) here
}

Posts that helped me: here and here

Costa
  • 1,794
  • 1
  • 12
  • 21