C2B2 logo icon

Common Tomcat Problems and how To Fix Them

Working on Apache Tomcat support cases, we often come across customers with similar Tomcat issues. In this post, Ramya looks at some of the most common Tomcat problems, and gives some easy to implement advice.

In this post, I wanted to look at some of the more common (and simple to solve) issues we've come across when supporting customers with Apache Tomcat deployments. Whether you need help with Tomcat start-up issues, are facing excessive garbage collection and memory management issues, looking for Tomcat installation advice or facing deployment problems, hopefully, you'll find some useful tips! 

Tomcat Startup Issues

#1 When running the tomcat startup and shutdown batch files in windows operating system, getting "out of environment space" error. 

In Microsoft Windows Explorer, right-click on the startup.bat and shutdown.bat files. Select Properties, then select the Memory tab. Increase the Initial Environment field to something like 4096. Select Apply. 
After you select Apply, shortcuts will be created in the directory you use to start and stop the container. 

#2 Tomcat Server returned HTTP response code: 401 for URL. When you type ant install, these message appear:

Make sure that the user name and password in your build.properties file match a user name and password with the role of manager in the tomcat-users.xml file. 

#3 When using the command line startup.bat, a command prompt out then close automatically. 

 Type in "catalina.bat run" at the bin directory of the Apache Tomcat folder. Then, go to Run -> and type “systempropertiesadvanced”. This opens a dialog. Click on Environment Variables. In the system Variables, select CATALINA_HOME and edit the value if there is a "\"  at the end. 

Run the startup and we should be able to proceed now. 

Excessive garbage and memory management

Excessive garbage collection can stress your server's request-serving power. Starting the JVM with a higher maximum heap memory by using the -Xmx switch will decrease the frequency with which garbage collection occurs.

PermGen can be filled up if your application uses a large number of JSPs and servlets. The default size is 64MB, but this can be increased by using the -XX:MaxPermSize= 256m. Try doubling or quadrupling the size, and see if that eliminates the error messages.

For more information refer https://wiki.apache.org/tomcat/FAQ/Memory

Installation issues

#1 When trying to install Tomcat as a service with the service.bat file in CATALINA_HOME\bin\ , it shows “Failed installing 'tomcat 7' service”  error. 

In these cases check the port in server.xml. First, try to remove any other Tomcat service already installed using service.bat remove. Second, install the service service.bat install and voilà!

Deployment issues 

#1 Failure to run client application. The browser reports that the page cannot be found (HTTP 404).

The startup script starts the task in the background, and then returns the user to the command line prompt immediately. Even though you are returned to the command line, the startup script may not have completely started Tomcat.

If the Web Client does not run immediately, wait up to a minute and then retry to load the Web client.  

#2 The localhost Machine Is Not Found. Browser report HTTP 404. 

Sometimes when you are behind a proxy, the firewall will not let you access the localhost machine. To fix this, change the proxy setting so that it does not use the proxy to access localhost. 

To do this change in browser, select Edit -> Preferences -> Advanced -> Proxies and select No Proxy for: localhost.

In Internet Explorer, select Tools -> Internet Options -> Connections -> LAN Settings. 

#3 "Build Failed: Application Already Exists at Path" Error 

When you enter ant install at a terminal prompt, you get this message: 

This application has already been installed. If you've made changes to the application since it was installed, use ant reload to update the application in Tomcat. 
 
#4 HTTP 500: No Context Error. Get a No Context Error when attempting to run a deployed application. 

This error means that Tomcat is loaded, but it doesn't know about your application. If you have not deployed the application, that would be the first step. If you have successfully deployed the application by running ant remove, ant build, ant install, ant reload, and you're still getting the error, read on. 

If Tomcat is loaded, but has not yet loaded all of the existing contexts, you will also get this error. Continue to select the Reload or Refresh button on your browser until either the application loads or you get a different error message. 

Server Connection issues

#1 HTTP 404 status or Cannot connect to server http://localhost:8080 

Open the control panel and make sure that Tomcat is running by selecting the processes tab. Make sure Tomcat is running on a port that is not being used in that moment by another program or service. It may be necessary to change Tomcat’s port which is 8080 by default.

Skype and many other programs also attempt to use port 8080. If you are having problems, change Tomcat’s port to be safe. 

Navigate to C:\tomcat\conf and open server.xml with Notepad++ or Notepad. 

Find all instances of the port that Tomcat is currently using (8080 by default) and replace it with a port that is between 1024 and 9999. Using a simple find and replace in your text editor might be fastest.

Restart Tomcat and be sure to reflect the new port in your URL - and you should have a fix!