You can find Tomcat and java version running on Linux either by executing the org.apache.catalina.util.ServerInfo class from catalina.jar or by executing version.sh shell script. The first solution will work on any operating system including Windows and UNIX because it's using a Java class from a catalina.jar file, which is platform-independent. Though, if you don't know how to run a class from the JAR file, you can check the steps here. Alternatively, you also have a version.bat file inside tomcat/bin directory to check the version of Tomcat in Windows.
When you run this script in Linux or Windows it prints information about tomcat version, the java version used to run tomcat, Server built to date, OS name, OS Version, architecture, JVM version, and JVM vendor, etc.
Behind the scene, this batch file is also running the ServerInfo class from catalina.jar but it set the necessary PATH and Classpath variable for you. It's much convenient to run either version.sh in Linux or version.bat in Windows to get the Tomcat version.
Solution 1 (Running ServerInfo class) :
a) go to tomcat installation directory and run following command :
Here is how you get tomcat version in Windows :
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41>java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo
Server version: Apache Tomcat/7.0.41
Server built: Jun 6 2013 11:16:08
Server number: 7.0.41.0
OS Name: Windows 8
OS Version: 6.2
Architecture: amd64
JVM Version: 1.7.0_51-b13
JVM Vendor: Oracle Corporation
By the way, If you don't have catalina.jar in your tomcat/lib folder then you may get :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/catalina/util/ServerInfo
Caused by: java.lang.ClassNotFoundException: org.apache.catalina.util.ServerInfo
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
In that case, just check if version.sh or vesion.bat is present in tomcat/bin directory as suggested in our second solution. But, if you are getting this error even if you have catalina.jar in the tomcat/lib folder, please check out some of the steps given in my article 3 ways to solve NoClassDefFoundError in Java to troubleshoot further.
Solution 2 (using version.sh or version.bat) :
1) Go to tomcat/bin directory
2) Execute version.sh in Linux or version.bat in Windows
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41\bin>version.bat
Using CATALINA_BASE: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41"
Using CATALINA_HOME: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41"
Using CATALINA_TMPDIR: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.7.0_51"
Using CLASSPATH: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41\bin\bootstrap.jar;C:\Program Files\Apache Soft
ware Foundation\Apache Tomcat 7.0.41\bin\tomcat-juli.jar"
Server version: Apache Tomcat/7.0.41
Server built: Jun 6 2013 11:16:08
Server number: 7.0.41.0
OS Name: Windows 8
OS Version: 6.2
Architecture: amd64
JVM Version: 1.7.0_51-b13
JVM Vendor: Oracle Corporation
It's important to define either JAVA_HOME or JRE_HOME to run version.bat, otherwise, you will get following error :
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41\bin>version.bat
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variables is needed to run this program
The "Server version" field is the Tomcat version running on that machine. version.sh also prints additional information related to JVM and JRE version used to run tomcat in Linux or Windows.
If you are developing Java application in Tomcat, you can also learn more about Tomcat by reading Developing Java application in Tomcat, Eclipse Mars, and MySQL.
That's all about how to find Tomcat version in Linux and Windows. By using version.sh, you can also find the Java version used to run tomcat. If you want to use a platform independent approach then just run ServerInfo class from catalina.jar, which you can find inside tomcat/lib directory. If you don't have that JAR in lib directory then check for version.sh or version.bat file in tomcat/bin directory, running them will give you all the information you want about your tomcat installation.
References
Apache Tomcat Official Website
Other Apache Tomcat tutorials and Guides you may like:
When you run this script in Linux or Windows it prints information about tomcat version, the java version used to run tomcat, Server built to date, OS name, OS Version, architecture, JVM version, and JVM vendor, etc.
Behind the scene, this batch file is also running the ServerInfo class from catalina.jar but it set the necessary PATH and Classpath variable for you. It's much convenient to run either version.sh in Linux or version.bat in Windows to get the Tomcat version.
2 ways to find Apache Tomcat version in UNIX and Windows
As discussed in the last paragraph, we need to run the ServerInfo class from catalinar.jar to get the Tomcat version and other meta-data. Let's see examples of using these two ways to find tomcat and java version running tomcat in Windows first, followed by Linux and UNIX.Solution 1 (Running ServerInfo class) :
a) go to tomcat installation directory and run following command :
$ java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo
Here is how you get tomcat version in Windows :
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41>java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo
Server version: Apache Tomcat/7.0.41
Server built: Jun 6 2013 11:16:08
Server number: 7.0.41.0
OS Name: Windows 8
OS Version: 6.2
Architecture: amd64
JVM Version: 1.7.0_51-b13
JVM Vendor: Oracle Corporation
By the way, If you don't have catalina.jar in your tomcat/lib folder then you may get :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/catalina/util/ServerInfo
Caused by: java.lang.ClassNotFoundException: org.apache.catalina.util.ServerInfo
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
In that case, just check if version.sh or vesion.bat is present in tomcat/bin directory as suggested in our second solution. But, if you are getting this error even if you have catalina.jar in the tomcat/lib folder, please check out some of the steps given in my article 3 ways to solve NoClassDefFoundError in Java to troubleshoot further.
Solution 2 (using version.sh or version.bat) :
1) Go to tomcat/bin directory
2) Execute version.sh in Linux or version.bat in Windows
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41\bin>version.bat
Using CATALINA_BASE: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41"
Using CATALINA_HOME: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41"
Using CATALINA_TMPDIR: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.7.0_51"
Using CLASSPATH: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41\bin\bootstrap.jar;C:\Program Files\Apache Soft
ware Foundation\Apache Tomcat 7.0.41\bin\tomcat-juli.jar"
Server version: Apache Tomcat/7.0.41
Server built: Jun 6 2013 11:16:08
Server number: 7.0.41.0
OS Name: Windows 8
OS Version: 6.2
Architecture: amd64
JVM Version: 1.7.0_51-b13
JVM Vendor: Oracle Corporation
It's important to define either JAVA_HOME or JRE_HOME to run version.bat, otherwise, you will get following error :
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.41\bin>version.bat
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variables is needed to run this program
The "Server version" field is the Tomcat version running on that machine. version.sh also prints additional information related to JVM and JRE version used to run tomcat in Linux or Windows.
If you are developing Java application in Tomcat, you can also learn more about Tomcat by reading Developing Java application in Tomcat, Eclipse Mars, and MySQL.
That's all about how to find Tomcat version in Linux and Windows. By using version.sh, you can also find the Java version used to run tomcat. If you want to use a platform independent approach then just run ServerInfo class from catalina.jar, which you can find inside tomcat/lib directory. If you don't have that JAR in lib directory then check for version.sh or version.bat file in tomcat/bin directory, running them will give you all the information you want about your tomcat installation.
References
Apache Tomcat Official Website
Other Apache Tomcat tutorials and Guides you may like:
- How to configure HTTPS in Tomcat 6 and 7? (tutorial)
- How to setup JNDI database connection pool in Tomcat? (guide)
- Difference between a Web server, Application server and Servlet container? (answer)
- How to fix java.lang.OutOfMemoryError: PermGen space in Tomcat (guide)
- How to fix java.net.BindException: Cannot assign requested address: JVM_Bind in Tomcat (fix)
- How to fix java.lang.OutOfMemoryError: java heap space in Tomcat (tutorial)
- How to fix ThreadLocal memory leak in Tomcat? (solution)
- How to fix java.net.SocketException: Too many open files in Tomcat? (tutorial)
- How to fix java.net.BindException: Address already in use: JVM_Bind:8080 (solution)
- Why you shouldn't call System.exit() in Tomcat? (article)
No comments:
Post a Comment