How to get Tomcat version number in Java
How do I get the Tomcat / Catalina version number in JAVA?
I have seen many ways to do this using the command line, etc., but this is not the code I can use, I also cannot use catalina.path as the version number has been removed from the path.
Also note that I want to use the in-code version, so the various JSP solutions I've looked at also don't work for me.
thank
source to share
From JSP
In the jsp file, you can print the version like this:
Tomcat Version : <%= application.getServerInfo() %>
Output:
Tomcat Version : Apache Tomcat/8.0.14
Outside JSP (any Java code)
If you want it outside of the JSP (like in a servlet or listener or w / e) take a look at the org.apache.catalina.util.ServerInfo
class, it has some useful static methods:
System.out.println(ServerInfo.getServerBuilt());
System.out.println(ServerInfo.getServerInfo());
System.out.println(ServerInfo.getServerNumber());
Output:
Sep 24 2014 09:01:51
Apache Tomcat/8.0.14
8.0.14.0
So what do you really want ServerInfo.getServerNumber()
.
Note:
The class ServerInfo
also has a method main()
, so it can be run as a standalone application:
java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo
Output example:
Server version: Apache Tomcat/8.0.14
Server built: Sep 24 2014 09:01:51
Server number: 8.0.14.0
OS Name: Windows 7
OS Version: 6.1
Architecture: x86
JVM Version: 1.7.0_55-b13
JVM Vendor: Oracle Corporation
source to share