Idea packaged into war package deployed to tomcat and access path issues (illustration and text)

Idea packaged into war package deployed to tomcat and access path issues (illustration and text)

The most important thing for idea to package a web project into a war is to configure atrificats.

First open file -> project structure

After creation, the output directory is the path of the output war package. The name can be anything you want, then click the green + to open the directory content

Select the webapp directory and remember to check include in project build

After clicking OK, create a new configuration

Select artificats

In this way, even if the configuration is completed, after clicking run to execute, just find the war package in the folder set in the previous output directory. Put the war package in the webapp directory of tomcat, and then start tomcat to access the project.

The access address of the project is localhost:8080/your war package name/index

What I want to say here is that since the name of the war package determines the access address, when using pure html+css+js to write a page, it is best to add your project name (that is, your final war package name) to the resource reference address of the page, for example, referencing a js file:

<link rel="stylesheet" href="/layui/css/layui.css" media="all" />

At this time, if you hold down the ctrl key and hover the mouse over the file path, there will be a clickable prompt.

However, when the project is deployed on tomcat, the war package is equivalent to adding a folder named your war package. At this time, the original reference will prompt that the file cannot be found. At this time, we should reference it like this:

<link rel="stylesheet" href="/war package name/layui/css/layui.css" media="all" />

When your reference address contains .., for example:

<script type="text/javascript" src="../../page/user/editUser.js"></script>

It should be modified like this:

<script type="text/javascript" src="../../war package name/backstage/page/user/editUser.js"></script>

But here comes the problem. When configured in this way, the file can be found when deployed to tomcat, but after starting tomcat debugging in local idea development, the file cannot be found. At this time, you should configure the application context and start it. And make sure it is consistent with the file path when deployed to Tomcat, so there is no need to modify the address of the front-end page when deploying to Tomcat. (jsp does not need to consider this problem because jsp can obtain the root path).

If the application context is just "/", then it is equivalent to placing all files under tomcat's webapp and accessing them directly through localhost:8080/file.

This is the end of this article about packaging idea into a war package and deploying it to Tomcat and the access path problem (detailed explanation with pictures and text). For more relevant idea war package deployment to Tomcat content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • idea combines docker to realize image packaging and one-click deployment
  • A brief analysis of SpringBoot packaging and uploading to docker and implementing multi-instance deployment (IDEA version)
  • How to package jar with Intellij idea2020
  • When running the jar packaged by idea, it reports "There is no main manifest attribute in XXX"
  • The complete steps to package the idea project into a jar file
  • Detailed explanation of various ways to package jar with idea
  • How to package the project into docker through idea

<<:  js method to realize shopping cart calculation

>>:  Summary of SQL query optimization knowledge points for MySQL tens of millions of big data

Recommend

MySQL 8.0.20 compressed version installation tutorial with pictures and text

1. MySQL download address; http://ftp.ntu.edu.tw/...

Detailed explanation of gcc command usage under Linux system

Table of contents 1. Preprocessing 2. Compilation...

About front-end JavaScript ES6 details

Table of contents 1. Introduction 1.1 Babel Trans...

Vite2.0 Pitfalls

Table of contents Vite project build optimization...

JavaScript Basics Series: Functions and Methods

Table of contents 1. The difference between funct...

Implementation of VUE infinite level tree data structure display

Table of contents Component recursive call Using ...

Use of provide and inject in Vue3

1. Explanation of provide and inject Provide and ...

MySQL integrity constraints definition and example tutorial

Table of contents Integrity constraints Definitio...

Vue echarts realizes horizontal bar chart

This article shares the specific code of vue echa...

Detailed explanation of how to introduce custom fonts (font-face) in CSS

Why did I use this? It all started with the makin...

WeChat applet realizes multi-line text scrolling effect

This article example shares the specific code for...

Some tips on website design

In fact, we have been hearing a lot about web des...