[java] Tomcat: How to find out running tomcat version

I'm trying to get Appfuse + tomcat + jRebel working.

Appfuse by default uses Cargo to download tomcat (ver. 7.0.33) and deploy the application to it. I wish to use an already installed tomcat (ver. 7.0.27) instead of the downloaded one. I made the change following the appfuse FAQ.

After deploying with mvn cargo:run, how can I know that the actual running tomcat is indeed 7.0.27?

I used to type a wrong URL (ex. localhost:8080/dfsfsdf) to see it in the error page, but now it shows nothing.

My $CATALINA_HOME points to my own tomcat 7.0.27. sorry forgot to mention, it's for Windows

Update:

Since this question had become somehow popular, I would like to explain why that accepted answer. simple, it was the first one which solved my problem.

looking at the title of the question, @Tech Junkie and @CPU 100 really have the best answer, but not for the scenario I was encountered. (I was wanting to know if mvn cargo:run runs my installed tomcat or a "project embeded" tomcat) :)

This question is related to java tomcat appfuse

The answer is


The version of currently running Tomcat

If you set the environtment variable - %CATALINA_HOME%, then Windows :

>> cd %CATALINA_HOME%\bin
>> version

Alternatively,

java.exe -cp lib\catalina.jar org.apache.catalina.util.ServerInfo

MY SETTING --- Hope yours will be similar to as follows

%CATALINA_HOME% --- C:\Program Files\Tomcat\apache-tomcat-8.0.28

OUTPUT

Server version: Apache Tomcat/8.0.28 Server built: Oct 7 2015 18:25:21 UTC Server number: 8.0.28.0 OS Name: Windows 7 OS Version: 6.1 Architecture: amd64 JVM Version: 1.8.0_111-b14 JVM Vendor: Oracle Corporation


Windows task manager > Processes > find tomcat > right click > open file location > if you run Tomcat7w.exe it is visible at description.

Tomcat should running to be visible at Processes if not at Windows Vista/7 go to task manager > tab (services) find tomcat start it and then processes.


Open your tomcat home page (Usually localhost:8080)

You will see something like this:

enter image description here


You can find out the server information through its status page:

{running-tomcat-url}/manager/status

On that page you can see the version of Java on which your Tomcat runs

Note: I have also pasted this answer on Tomcat6 and JRE7 compatibility issue. Unsupported major.minor version 51.0


To know exact tomcat version alone, just visit vi tomcat/BUILDING.txt


Though this is not recent, I thought, my answer can still help others:

cd tomcat/lib 
java -cp catalina.jar org.apache.catalina.util.ServerInfo

and that's it.

Server version: Apache Tomcat/7.0.30
Server built:   May 23 2013 02:54:10
Server number:  7.0.30.0
OS Name:        Linux
OS Version:     3.13.0-36-generic
Architecture:   amd64
JVM Version:    1.7.0_65-b32
JVM Vendor:     Oracle Corporation

This one command which you can check almost everything:

java -cp tomcat/lib/catalina.jar org.apache.catalina.util.ServerInfo

or

tomcat/bin/catalina.sh version

And the output looks like this

Server version: Apache Tomcat/8.5.24
Server built:   Nov 27 2017 13:05:30 UTC
Server number:  8.5.24.0
OS Name:        Linux
OS Version:     4.4.0-137-generic
Architecture:   amd64
JVM Version:    1.8.0_131-b11
JVM Vendor:     Oracle Corporation

Enter 404.jsp or non-existent.jsp.

Get Tomcat/JBoss version number at bottom of page.


For Windows PowerShell command-line method of checking running version(s) of Tomcat service:

(get-service Tomcat*).DisplayName

Sample output...

Apache Tomcat 8.5 Tomcat8

If also want to know additional details including the location of folder where service running at:

Get-WmiObject win32_service | Where-Object {$_.Name -like 'Tomcat*'} | select Name, DisplayName, State, PathName

Sample output...

Name    DisplayName               State   PathName
----    -----------               -----   --------
Tomcat8 Apache Tomcat 8.5 Tomcat8 Running "C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin\Tomcat8.exe" /...

We are running in a Windows environment and I had to find a way to get the Tomcat version outside of the Java environment. Without knowing the version, I could not determine the directories. I finally found the best way was to query the Tomcat service using:

C:\temp>sc query | find /I "tomcat"
SERVICE_NAME: Tomcat6
DISPLAY_NAME: Apache Tomcat 6.0 Tomcat6


You can simply open http://localhost:8080/ in your web browser and this will open Tomcat welcome page that shows running Tomcat version like this:

Apache Tomcat/7.0.42
  • I assume that your Tomcat is running on port 8080

execute the script in your tomcat/bin directory:

sh tomcat/bin/version.sh

Server version: Apache Tomcat/7.0.42
Server built:   Jul 2 2013 08:57:41
Server number:  7.0.42.0
OS Name:        Linux
OS Version:     2.6.32-042stab084.26
Architecture:   amd64
JVM Version:    1.7.0_21-b11
JVM Vendor:     Oracle Corporation

run the following

/usr/local/tomcat/bin/catalina.sh version

its response will be something like:

Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /var/tmp/
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_PID:    /var/catalina.pid
Server version: Apache Tomcat/7.0.30
Server built:   Sep 27 2012 05:13:37
Server number:  7.0.30.0
OS Name:        Linux
OS Version:     2.6.32-504.3.3.el6.x86_64
Architecture:   amd64
JVM Version:    1.7.0_60-b19
JVM Vendor:     Oracle Corporation

To find out the Tomcat version, find this file – version.sh for *nix or version.bat for Windows. This version.sh file is normally located in the Tomcat bin folder.

phpmongodb@kumar:/usr/share/tomcat7/bin$ ./version.sh 

Note

If you are not sure where is the version.sh file, try this command :

sudo find / -name "version.sh"

Find out everything about Tomcat7.

sudo find / -name "tomcat7"

Using the release notes

In the main Tomcat folder you can find the RELEASE-NOTES file which contains the following lines (~line 20-21):

                Apache Tomcat Version 8.0.22
                        Release Notes

Or you can get the same information using command line:

  • Windows:

    type RELEASE-NOTES | find "Apache Tomcat Version"
    

    Output:

                 Apache Tomcat Version 8.0.22
    
  • Linux:

    cat RELEASE-NOTES | grep "Apache Tomcat Version"
    

    Output:

                 Apache Tomcat Version 8.0.22
    

I have this challenge when working on an Ubuntu 18.04 Linux server.

Here's how I fixed it:

Run the command below to determine the location of your version.sh file:

sudo find / -name "version.sh"

For me the output was:

/opt/tomcat/bin/version.sh

Then, using the output, run the file (version.sh) as a shell script (sh):

sh /opt/tomcat/bin/version.sh

That's all.

I hope this helps


I know it is maybe too late for this, but this could be usefull: If you try to know Apache Tomcat Server version from Java code, you can use:

from a HttpServlet:

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
    getServletContext().getServerInfo()
}

from a ServletContextListener:

public void contextInitialized(ServletContextEvent event)  { 
    event.getServletContext().getServerInfo();      
}

Simply start tomcat and search for "Server version name" in catalina.logs and you will get version of your tomcat. For example:

"Mar 07, 2019 11:25:40 AM org.apache.catalina.startup.VersionLoggerListener log INFO: Server version name: Apache Tomcat/9.0.16"


If Tomcat is installed as a service, try:

sudo /etc/init.d/tomcat version

Swap out "tomcat" with the actual name of the service.


On Windows just cmd

C:\Program Files (x86)\Extensis\Portfolio Server\applications\tomcat\bin>version


  1. Try parsing or executing the Tomcat_home/bin directory and look for a script named version.sh or version.bat depending on your operating system.
  2. Execute the script ./version.sh or version.bat

If there are no version.bat or version.sh then use a tool to unzipping JAR files (\tomcat\server\lib\catalina.jar) and look in the file org\apache\catalina\util\lib\ServerInfo.properties. the version defined under "server.info=".


For securing Tomcat from hackers, it's recommended that we try a few steps at hiding the tomcat version information. The OWASP project suggests a few steps. https://www.owasp.org/index.php/Securing_tomcat . If a tomcat installation is thus protected, then only 1 of the above answers will show the version of tomcat.
i.e going through the $TOMCAT_HOME\RELEASE-NOTES file where the version number is clearly announced.

I had one such protected server and only the RELEASE-NOTES file revealed the version of the tomcat. all other techniques failed to reveal the version info.


run on terminal of the Unix server

w3m http://localhost:8080/

to quit press q and next y


In Unix-like environments, I also recommend checking the actual running process command line:

$ ps aux | grep java

...
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djava.util.logging.config.file=/srv/tomcat-instances/bla/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Xmx4096M -XX:+UseConcMarkSweepGC -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n -Xmx4096m -Xms4096m -XX:MaxPermSize=2048m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=8090 -Dcom.sun.management.jmxremote.rmi.port=8090 -Djava.rmi.server.hostname=localhost -Djava.endorsed.dirs=/opt/apache-tomcat-8.0.47/endorsed -classpath /opt/apache-tomcat-8.0.47/bin/bootstrap.jar:/opt/apache-tomcat-8.0.47/bin/tomcat-juli.jar -Dcatalina.base=/srv/tomcat-instances/bla -Dcatalina.home=/opt/apache-tomcat-8.0.47 -Djava.io.tmpdir=/tmp/tomcat8-bla-tmp org.apache.catalina.startup.Bootstrap start
...

One can run on subtle weird behaviors due to (operating system) environment variables and (Java) system properties being set to unexpected values. I had a situation where due to an outdated Tomcat setenv.sh, A Tomcat 8 started with classes from a Tomcat 7 on the classpath. Make sure that in the process command line options such as -Dcatalina.base, -Dcatalina.home and -classpath make sense.


In Linux to check the tomcat version

cd /opt/tomcat/bin

./catalina.sh version

For windows machine 
Go to the tomcat directory C:\apache-tomcat-x.0.xx\bin
    bin>version.bat
    Using CATALINA_BASE:   "C:\apache-tomcat-x.0.xx"
    Using CATALINA_HOME:   "C:\apache-tomcat-x.0.xx"
    Using CATALINA_TMPDIR: "C:\apache-tomcat-x.0.xx\temp"
    Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_65"
    Using CLASSPATH:       "C:\apache-tomcat-x.0.xx\bin\bootstrap.jar;C:\apache-tomcat-x.0.xx\bin\tomcat-juli.jar"
    Server version: Apache Tomcat/7.0.53





For Linux Machine 
Go to the tomcat directory /usr/mack/apache-tomcat-x.0.xx/bin
    # ./version.sh
    Using CATALINA_BASE:   /usr/mack/apache-tomcat-x.0.xx
    Using CATALINA_HOME:   /usr/mack/apache-tomcat-x.0.xx
    Using CATALINA_TMPDIR: /usr/mack/apache-tomcat-x.0.xx/temp
    Using JRE_HOME:        /usr/java/jdk1.7.0_71/jre
    Using CLASSPATH:       /usr/mack/apache-tomcat-x.0.xx/bin/bootstrap.jar:/usr/mack/apache-tomcat-x.0.xx/bin/tomcat-juli.jar
    Server version: Apache Tomcat/7.0.56

If Tomcat is installed as a service:

#sudo /etc/init.d/tomcat version

Another option is view release notes from tomcat,applicable to linux/window

{Tomcat_home}/webapps/ROOT/RELEASE-NOTES.txt

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to tomcat

Jersey stopped working with InjectionManagerFactory not found The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat Spring boot: Unable to start embedded Tomcat servlet container Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists Spring Boot application in eclipse, the Tomcat connector configured to listen on port XXXX failed to start Kill tomcat service running on any port, Windows Tomcat 8 is not able to handle get request with '|' in query parameters? 8080 port already taken issue when trying to redeploy project from Spring Tool Suite IDE 403 Access Denied on Tomcat 8 Manager App without prompting for user/password Difference between Xms and Xmx and XX:MaxPermSize

Examples related to appfuse

Tomcat: How to find out running tomcat version