How to implement hot deployment and hot start in Eclipse/tomcat

How to implement hot deployment and hot start in Eclipse/tomcat

1. Hot deployment: It means redeploying the entire project while the container is running. In this case, the entire memory will generally be cleared and reloaded. In simple terms, Tomcat or other web servers will help us reload the project. This method may cause session loss and other situations.

2. Hot loading: It means reloading and changing the compiled class while the container is running. In this case, the memory will not be cleared and the session will not be lost, but it is easy to cause memory overflow or fail to find the method. Because memory cannot be converted into objects. Generally, changing the structure and model of a class will cause exceptions, but changing existing variables and methods will not cause problems.

Eclipse configuration hot start:

In the process of hot deployment and hot loading based on Java, class loaders play an important role. A class loader cannot reload an already loaded class, otherwise a java.lang.LinkageError will be reported, but the class can be loaded again into a running application as long as a new class loader instance is used. Generally, debug mode supports hot loading.

But here I encountered a situation where Eclipse was started with debug but there was no hot loading, which was very time-consuming for development because every change to the class file required recompilation. Here I will give a brief introduction on how to use eclipse for hot loading:

Start eclicpse and find the following directory

Open server.xml and find

Copy the code as follows:
<Context docBase="dreamlive" path="/ROOT" reloadable="true" crossContext="true" source="org.eclipse.jst.jee.server:dreamlive"/>

This line of code, when you deploy a new project, docBase and source will change accordingly. Now it is still in the hot deployment state, so each time the class file is changed, it will be automatically compiled, which is time-consuming. Next, let's change the configuration:

Copy the code as follows:
<Context docBase="dreamlive" path="/ROOT" reloadable="false" crossContext="true" source="org.eclipse.jst.jee.server:dreamlive"/></Host>

Change reloadable to false and add crossContext="true" to enable hot start. Note: You need to start with debug.

However, we need to change this configuration every time we deploy a new project. We can observe the dynamic changes of the server.xml file every time a new project is deployed. After the setting is completed, if the hot loading of the project does not take effect, check eclipse-->project-->Build Automatically and add automatic compilation.

The meaning of each attribute is attached below

  • path indicates your access path
  • docBase indicates your storage path
  • debug sets the debug level to 0, which provides the least information, and 9, which provides the most information.
  • When reloadable=true, when web.xml or class is changed, it will be automatically reloaded without restarting the service
  • crosscontext="true" means that different configured contexts share a session (optional)

Tomcat configuration hot start

The specific method is as follows:

Step 1: In the Tomcat installation directory, modify the Host configuration in conf/server.xml and set its reloadable attribute to true, that is, add reloadable="true" to the Host tag and restart Tomcat to make the configuration file take effect.

Step 2: Add to the web.xml file in the conf folder

<init-param>
 <param-name>development</param-name>
 <param-value>true</param-value>
</init-param>

Step 3: Restart the Tomcat server to make the changes take effect.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the problem that eclipse deploys tomcat server and cannot start
  • Solution to the problem that SpringBoot application cannot be started when deployed to Tomcat
  • Learn how to deploy and start multiple tomcats and migrate projects in one article

<<:  Problems encountered by MySQL nested transactions

>>:  Vue implements click and passes in event objects and custom parameters at the same time

Recommend

A few front-end practice summaries of Alipay's new homepage

Of course, it also includes some personal experien...

Docker enables multiple port mapping commands

as follows: docker run -d -p 5000:23 -p 5001:22 -...

Explanation of the new feature of Hadoop 2.X, the recycle bin function

By turning on the Recycle Bin function, you can r...

Element uses scripts to automatically build new components

Table of contents background How does element-ui&...

Detailed explanation of MySQL Strict Mode knowledge points

I. Strict Mode Explanation According to the restr...

Several principles for website product design reference

The following analysis is about product design pr...

MySQL FAQ series: When to use temporary tables

Introduction to temporary tables What is a tempor...

Some wonderful uses of URL objects in JavaScript

Table of contents Preface Parsing parameters Modi...

The difference and introduction of ARGB, RGB and RGBA

ARGB is a color mode, which is the RGB color mode...

Using CSS3 to create header animation effects

Netease Kanyouxi official website (http://kanyoux...

HTML sample code for implementing tab switching

Tab switching is also a common technology in proj...

The shortest JS to determine whether it is IE6 (IE writing method)

Commonly used JavaScript code to detect which ver...

Pure CSS code to achieve flow and dynamic line effects

Ideas: An outer box sets the background; an inner...

A brief analysis of Linux network programming functions

Table of contents 1. Create a socket 2. Bind sock...