This question already has an answer here:
- how to find out running tomcat version 22 answers
How do I get the Tomcat/Catalina version number in JAVA?
I've seen lots of how to do it via command line etc. but that's not code I can use, I also cannot use catalina.path as the version number has been stripped from the path.
Please also note I want to use the version in code, so the various JSP solutions that I've looked at also do not work for me.
Thanks
From a JSP
In a jsp file you can print out the version like this:
Output:
Outside of JSP (Any Java Code)
If you want it outside of a JSP (e.g. in a Servlet or listener or w/e) take a look at the
org.apache.catalina.util.ServerInfo
class, it has some nice static methods:Output:
So what you really want is
ServerInfo.getServerNumber()
.Note:
The
ServerInfo
class also has amain()
method so it can be run as a standalone application too:Example output:
Try to put this in your JSP
<%= application.getServerInfo() %>
Look at this