Pit encountered by idea running Maven multi module project

Time:2020-3-11

engineering structure

Pit encountered by idea running Maven multi module project

Check webui module

Pit encountered by idea running Maven multi module project
Pay attention to the red box part. For normal web projects, the folder style should be as follows:
Pit encountered by idea running Maven multi module project
Note that the webapp folder has a small blue dot. Only in this way can this module be considered as a web module by idea. Since our project is not a web project, we need to start a wool, so we need to make the small blue dot first.

Turn module into web project

Select the webui module and press F4 to open the settings dialog box and select modules.
Pit encountered by idea running Maven multi module project
clickPit encountered by idea running Maven multi module project(select the webui module, and then click the plus sign) and select web
Pit encountered by idea running Maven multi module project
Set the path of the red font in the following figure. Set 1, then 2
Pit encountered by idea running Maven multi module project
clickPit encountered by idea running Maven multi module projectObserve the path of the pop-up window
Pit encountered by idea running Maven multi module project
webui\web\WEB-INF\web.xmlThis path does not exist in the webui module at all, so at this time, you need to modify the path to point to the correct location, and select the correct deployment descriptor version. Use 2.5 here.
clickPit encountered by idea running Maven multi module projectSet the path in the pop-up window.
Pit encountered by idea running Maven multi module project
Find the folder where the webui module is located, find the webapp folder, find web.xml (be sure to find web.xml), select it, click OK, and then set it as shown in the figure
Pit encountered by idea running Maven multi module project
Set the path marked in red 2. The operation mode is the same as that of 1. Note that the selected path is to the webapp folder, as shown in the following figure
Pit encountered by idea running Maven multi module project
At this time, if you look at the webapp folder, a small blue dot will appear
Pit encountered by idea running Maven multi module project

Set up artifacts

The small blue dot already exists, but at this time, the project still cannot run in Tomcat. You need to configure artifacts and put them in Tomcat (so it may not be standard. In fact, idea uses virtual tmocat instead of putting the war package into the webapp folder configured as Tomcat) to run. Select the webui module, press F4, and select artifacts
Pit encountered by idea running Maven multi module projectClickPit encountered by idea running Maven multi module project, and then operate as shown in the figure
Pit encountered by idea running Maven multi module projectClickFrom Modules...
Pit encountered by idea running Maven multi module projectClick OK
Pit encountered by idea running Maven multi module projectAdjust the red box Department path to point to the output path in the webui module. Here we usexxx\webui\target\, which is the output path of the webui module. You can also specify the module name, such asxxx\webui\target\modulesNameIn general, you do not need to specify it, because it will default to the above name, namely XXX: War expanded.Pit encountered by idea running Maven multi module projectClick OK

Configure Tomcat artifact

How to configure Tomcat in idea is not shown here. The default is that Tomcat has been configured. Open the configured Tomcat and clickPit encountered by idea running Maven multi module projectSelect artifact
Pit encountered by idea running Maven multi module projectClick OK
Pit encountered by idea running Maven multi module projectClick OK

Start Tomcat

An error will be reported during startup. The exception isjava.lang.ClassNotFoundException: Cannot find class:com.xxx.xxx.A。 Since webui is finally a published war package, other modules will be relied on in this war package, so the dependent modules should be set in the artifacts configuration.
Pit encountered by idea running Maven multi module project
Note classes. Add the dependencies of other modules to classes.
Expand the right module
Pit encountered by idea running Maven multi module project
Double click each modulecompile outputIn other words, add the compiled output path of each module to the classes of the webui module
Pit encountered by idea running Maven multi module project, click OK, and then try to start Tomcat. Normally, it should be started successfully. If the startup is not successful, clean the project, and then start it.