Reputation: 11765
I am making a java webapplication using eclipse and tomcat server. I want to know what happens when I run my website on Tomcat ? What are the steps Eclipse does in the background to run the application on tomcat.
This will help me understand when to switch off the server (while debugging) / when to clean the server etc.
I need to know what goes into the server so that I can get better at debugging.
Right now all I do is restart the server everytime something goes wrong. I have wasted enough time doing that. I guess I need to invest a little bit more time in understanding what happens behind the scenes.
Upvotes: 6
Views: 4183
Reputation: 18194
I will assume:
target/classes
is the target folder for compiled classessrc/main/webapp
is the web application content folderProject > Build Automatically
option is checkedEclipse is using exploded WAR deployment - i.e. the deployed application is deployed as a folder, not a single file archive. Application files are placed and loaded from ${workspace}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/
.
Publishing is a central process which is responsible for assembling and deploying the web application. When talking about local Tomcat, this means copying "web content, compiled classes, libraries, ..." into deployment directory (the one in .metadata
).
Eclipse is able to do partial publishing - i.e. when a single resource changes (e.g. some JSP), Eclipse will publish only that single file.
By default publish process is performed automatically when some resource changes. This can be modified in server settings (double click on the server name in Servers view).
If you change lets say src/main/webapp/resources/myApp/css/main.css
:
If you change JSP file:
If you change a java source file:
target/classes
You can turn of the auto-reloading feature in server settings on the Modules tab. Without auto-reloading you can still use hot swap feature, which is able to replace code in running JVM. This is possible only when method signatures are not changed.
If you want more advanced solution (i.e. not limited to changing just a method body) when it comes to reloading java changes, you should check projects like JRebel (not free).
Deployed application can get corrupted. It is worth noting, that when you want to clean completely compiled and published resources, you should:
Project > Clean...
- deletes target/classes
)Server > Clean...
- deletes deployment folder)Server > Clean Tomcat Work Directory...
- deletes compiled JSPs)Upvotes: 18