What happens when I run the application on tomcat in Eclipse

I am making a java web application using eclipse and a tomcat server. I want to know what happens when I launch my site on Tomcat? What are the steps that Eclipse takes in the background to run the application on tomcat.

This will help me understand when to shut down the server (during debugging) / when to clear the server, etc.

I need to know what is happening on the server so that I can debug better.

Now all I do is restart the server every time something goes wrong. I have spent enough time on this. I think I need to spend a little more time understanding what is going on behind the scenes.

+5
eclipse spring-mvc tomcat
source share
1 answer

Wednesday assumptions

I guess:

  • target/classes is the destination folder for compiled classes
  • src/main/webapp - web application content folder
  • Project > Build Automatically checked option

Deployment Directory

Eclipse uses a deployed WAR deployment — that is, a deployed application is deployed as a folder, not a single file archive. Application files are hosted and downloaded from ${workspace}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ .

Publishing house

Publishing is the central process that is responsible for building and deploying a web application. When it comes to local Tomcat, it means copying "web content, compiled classes, libraries ..." to the deployment directory (one in .metadata ).

Eclipse can do partial publishing — that is, when a single resource changes (for example, some JSP), Eclipse will only publish this single file.

By default, a process is published automatically when a resource changes. This can be changed in the server settings (double-click the server name in the Servers view).

Publishing setting

Static Resource Change

If you change, say src/main/webapp/resources/myApp/css/main.css :

  • after publication, the file is copied to the deployment folder Resource
  • instantly available for server clients

JSP file change

If you changed the JSP file:

  • after publishing, the file is copied to the deployment folder
  • Tomcat notices that the JSP file has changed and recompiles it.
  • modified JSP is ready to render content

Modify Java File

If you change the java source file:

You can enable the automatic reboot function in the server settings on the "Modules" tab. Without automatic rebooting, you can use the hot swap function , which can replace the code in the JVM startup. This is only possible when the method signatures are not changed.

Auto reloading feature

If you need a more advanced solution (i.e., not limited to replacing only the method body), when it comes to reloading java changes, you should check projects, for example JRebel (not free).

Cleaning

A deployed application may be corrupted. It is worth noting that when you want to clear fully compiled and published resources, you must:

  • Clear compiled classes ( Project > Clean... - removes target/classes )
  • Cleaning deployed files ( Server > Clean... - deleting the deployment folder)
  • Clear Tomcat working directory ( Server > Clean Tomcat Work Directory... - removes compiled JSPs)
+16
source share

All Articles