java读取tomcat,如何在Java中获取Tomcat版本号

本文介绍了如何在Java中获取Tomcat或Catalina的版本号,包括在JSP中直接输出版本号以及在Servlet或监听器等其他Java代码中使用org.apache.catalina.util.ServerInfo类的静态方法来获取版本信息。
摘要由CSDN通过智能技术生成

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:

Tomcat Version :

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值