Detailed tutorial on running Tomcat in debug mode in IDEA Maven project

Detailed tutorial on running Tomcat in debug mode in IDEA Maven project

1. Add the following dependencies in pom.xml

<dependency>
 <groupId>javax.servlet</groupId>
 <artifactId>javax.servlet-api</artifactId>
 <version>3.0.1</version>
 <scope>provided</scope> // This is the scope</dependency>
<dependency>
 <groupId>javax.servlet.jsp</groupId>
 <artifactId>jsp-api</artifactId>
 <version>2.2</version>
 <scope>provided</scope> // This is the scope</dependency>

Note: It needs to be placed in <dependencies></dependencies> , otherwise an error will be reported

I use mvn tomcat:run, which will lead to a problem: although I configure tomcat7, tomcat6 is used by default, and tomcat6 does not support jdk1.8. Here you need to add the tomcat7-maven-plugin plug-in. Note: If your version is tomcat7-maven-plugin 2.0, since it does not support jdk 1.8, just replace it with tomcat7-maven-plugin 2.2. Add the following code in pom.xml:

<plugin>
 <groupId>org.apache.tomcat.maven</groupId>
 <artifactId>tomcat7-maven-plugin</artifactId>
 <version>2.2</version>
</plugin>

That's it.

"IDEA maven cannot import static files such as css, js, img, etc."
Add in web.xml (add whatever files need to be intercepted)

<servlet-mapping>
 <servlet-name>default</servlet-name>
 <url-pattern>*.js</url-pattern>
 <url-pattern>*.css</url-pattern>
 <url-pattern>*.map</url-pattern>
 <url-pattern>*.jpg</url-pattern>
 <url-pattern>*.png</url-pattern>
 <url-pattern>*.eot</url-pattern>
 <url-pattern>*.svg</url-pattern>
 <url-pattern>*.ttf</url-pattern>
 <url-pattern>*.woff</url-pattern>
 <url-pattern>*.otf</url-pattern>
 <url-pattern>*.woff2</url-pattern>
 <url-pattern>*.gif</url-pattern>
</servlet-mapping>

Add to the jsp page:

<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
%>

Then you can directly reference bathPath, such as:

<link rel="stylesheet" href="<%=basePath%>/css/bootstrap.min.css" rel="external nofollow" type="text/css">

Tomcat created by Maven, running in debug mode

1. First enter the edit structure.

insert image description here

2. Select the green "+" sign and scroll down to find the "Maven" option and click it.

insert image description here

3. Select the project to be debugged.

insert image description here

4. Just run the debug program.

insert image description here

5. Copy this path + file directory and you can access it

insert image description here

Modify the front-end code of the Maven project, click somewhere else, and refresh the webpage without restarting Maven.

Note:

This deployment is only useful for jsp page modification, not for Servlet, and also cannot recognize html

This is the end of this article about the detailed tutorial on how to use debug mode to run Tomcat in IDEA Maven project. For more information about how to use debug mode to run Tomcat in IDEA Maven project, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The IDEA process has ended, exit code -1073741819 (0xC0000005) bug
  • Detailed explanation of IntelliJ IDEA 2020's Debug function
  • Detailed explanation of the reasons and solutions for IDEA starting tomcat port occupation (using debug mode)
  • Intellij idea remote debug connects tomcat to achieve single-step debugging
  • IDEA uses SpotBugs to find bugs in your code

<<:  Native js to achieve simple carousel effect

>>:  MySQL 8.0.20 installation tutorial and detailed tutorial on installation issues

Recommend

Summary of MySQL view principles and usage examples

This article summarizes the principles and usage ...

How to move a red rectangle with the mouse in Linux character terminal

Everything is a file! UNIX has already said it. E...

Mysql auto-increment primary key id is not processed in this way

Mysql auto-increment primary key id does not incr...

A simple way to change the password in MySQL 5.7

This is an official screenshot. After MySQL 5.7 i...

In-depth explanation of MySQL user account management and permission management

Preface The MySQL permission table is loaded into...

How to check where the metadata lock is blocked in MySQL

How to check where the metadata lock is blocked i...

What are HTML inline elements and block-level elements and their differences

I remember a question the interviewer asked durin...

How to use less in WeChat applet (optimal method)

Preface I am used to writing less/sass, but now I...

Summary of Nginx location and proxy_pass path configuration issues

Table of contents 1. Basic configuration of Nginx...