From a JSP
In a jsp file you can print out the version like this:
Tomcat Version : <%= application.getServerInfo() %>
Output:
Tomcat Version : Apache Tomcat/8.0.14
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:
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 you really want is ServerInfo.getServerNumber()
.
Note:
The ServerInfo
class also has a main()
method so it can be run as a standalone application too:
java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo
Example output:
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