获取 Java 应用服务器名称和版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7440706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:59:20  来源:igfitidea点击:

Get Java application server name and version

javaservletsweb

提问by nybon

I am writing a Web application with Java, and this WAR application may be deployed to different application servers, such as Tomcat/JBoss/Jetty/Weblogic.

我正在用Java编写一个Web应用程序,这个WAR应用程序可能会部署到不同的应用服务器上,比如Tomcat/JBoss/Jetty/Weblogic。

For diagnostic purpose, I'd like to implement a dynamic web page to collect various environment/system information so that customer can provide these information to support engineers for diagnostics.

出于诊断目的,我想实现一个动态网页来收集各种环境/系统信息,以便客户可以将这些信息提供给支持工程师进行诊断。

One piece of information that is useful is the application server name and version that this application gets deployed to, such as Tomcat 7.0, JBoss 5.1.0, Glassfish 3.0, etc.

一条信息是有用的是应用程序服务器的名称和版本,此应用程序部署到,如Tomcat 7.0JBoss 5.1.0Glassfish 3.0,等。

I just wonder if there is any standard wayto retrieve application server's name and version from different JEE application servers.

我只是想知道是否有任何标准方法可以从不同的 JEE 应用程序服务器中检索应用程序服务器的名称和版本。

回答by Yagnesh Agola

I have find some code for getting server information of where you deploy your application.
This code is written in Servlet to get server info in which it is running..

我找到了一些代码,用于获取有关您部署应用程序的位置的服务器信息。
这段代码是用 Servlet 编写的,用于获取运行它的服务器信息。

String str1 = getServletContext().getServerInfo();

String str1 = getServletContext().getServerInfo();

By this you will get the server name and the server's version info.

通过这个,您将获得服务器名称和服务器的版本信息。

I think it will some what help you..

我想这会对你有所帮助..

回答by Santosh

These type of information are always put in some MBean. Please check out the respect ive App Server's documentation about the the MBeans the provide. You can programmatically access the MBean using JMX APIs.

这些类型的信息总是放在一些MBean 中。请查看有关提供的 MBean 的相应 App Server 文档。您可以使用JMX API 以编程方式访问 MBean 。

回答by epoch

I don't think there is an easy way to do this, but I know you can identify tomcat from checking the System environment properties

我不认为有一种简单的方法可以做到这一点,但我知道您可以通过检查系统环境属性来识别 tomcat

 -- listing properties --
 java.util.logging.config.file=/home/willie/.netbeans/7.0/apache-tom...
 user.dir=/home/willie/apache-tomcat-7.0.14/bin
 java.runtime.version=1.6.0_26-b03
 java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment
 java.endorsed.dirs=/home/willie/apache-tomcat-7.0.14/end...
 os.arch=amd64
 java.io.tmpdir=/home/willie/.netbeans/7.0/apache-tom...
 java.naming.factory.url.pkgs=org.apache.naming
 os.name=Linux
 sun.jnu.encoding=UTF-8
 java.library.path=/usr/lib/jvm/java-6-sun-1.6.0.26/jre/...
 tomcat.util.scan.DefaultJarScanner.jarsToSkip=bootstrap.jar,commons-daemon.jar,tomc...
 java.specification.name=Java Platform API Specification
 java.class.version=50.0
 sun.management.compiler=HotSpot 64-Bit Tiered Compilers
 os.version=2.6.38-8-generic
 user.home=/home/willie
 user.timezone=Africa/Johannesburg
 catalina.useNaming=true
 java.awt.printerjob=sun.print.PSPrinterJob
 java.specification.version=1.6
 file.encoding=UTF-8
 catalina.home=/home/willie/apache-tomcat-7.0.14
 user.name=willie
 java.class.path=/home/willie/apache-tomcat-7.0.14/bin...
 java.naming.factory.initial=org.apache.naming.java.javaURLContext...
 sun.security.krb5.debug=false
 package.definition=sun.,java.,org.apache.catalina.,org.a...
 java.vm.specification.version=1.0
 sun.arch.data.model=64
 java.home=/usr/lib/jvm/java-6-sun-1.6.0.26/jre
 sun.java.command=org.apache.catalina.startup.Bootstrap...
 catalina.base=/home/willie/.netbeans/7.0/apache-tom...
 file.separator=/
 java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport...
 common.loader=${catalina.base}/lib,${catalina.base}..

you can check for tomcat/jetty/jboss... specific entries and determine the version and server by that means

您可以检查 tomcat/jetty/jboss... 特定条目并通过这种方式确定版本和服务器