Tomcat in Eclipse: 6 popular “how to” questions
Learning a new technology is always a hard process. This process becomes even more difficult when you are trying to learn two technologies which are going to interact with each other. Tomcat and Eclipse are ones of the most popular pre-requirements in the Java EE development. Therefore to be a professional developer you need to know how to perform the most required actions with this pair and how to make some configurations.
1. How to add Tomcat in Eclipse?
The simplest way is to download Eclipse IDE for Java EE Developers. There if you create a new Dynamic Web Project, Eclipse will download and install Tomcat automatically. But what if you want to do this by yourself?
- Firstly you need to download the latest version of Tomcat and install it on your computer. Don’t forget the directory of the newly installed Tomcat
- Then open Eclipse and on the main menu choose Window -> Preferences.
- In the “Preferences” window select Server -> Runtime Environments from the left panel.
- Click on the “Add..” button, after that select the version of Tomcat you have already installed.
- Click on the “Next” button, specify the path to the installed Tomcat and press the “Finish” button.
That’s it. Now you can find the server in the “Server” view in your Eclipse.
2. Where is Eclipse-Tomcat working directory?
It’s seems ridiculous when you are working with Tomcat in Eclipse and you don’t know where your server is. In order to find this out, you need to make several simple steps:
- Open the “Server” view in Eclipse.
- Select the server the location of which you want to know.
- Double click on the server.
- In the opened window select the “Server location” section.
- Take notice of the “Server path” field.
Usually this path looks like this: %eclipse_work_space%\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
3. Where is a log file in Tomcat?
The location of the logs directory in Tomcat (integrated with Eclipse): %eclipse_work_space%\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\logs
4. How to change Tomcat port in Eclipse?
The first way:
To change the HTTP port you should to repeat the first three steps from paragraph #2, then open the “Port” section and set the value for “HTTP/1.1” field (by default value is 8080) to that you want to use.
The second way:
Navigate to %eclipse_work_space%\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf
Open server.xml and find the following string:
Modify the value of the “port” attribute in order to specify the port you need to use.
5. Where to put WAR file in Tomcat?
- If you integrate Tomcat with Eclipse: %eclipse_work_space%\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
- If you want to deploy WAR file in standalone Tomcat: %server_location%\webapps
6. Tomcat debug mode in Eclipse
In order to launch Tomcat in debug mode from Eclipse, click on the button with bug icon in the “Server” view (view the image below for more details).