Idea+maven+tomcat deploys the first tomcat project
IDEA creates a Maven project and deploys it, IDEA configures Tomcat, and creates a java source folder.
This tutorial is suitable for newbies who are just using IDEA. Personal website http://www.duomao.xyz hope everyone supports
1. Create a Maven project
-
As shown below, after opening the idea, file -> new -> project
-
As shown in the figure below, on the new project page that pops up, select maven -> check Create from artifactype -> check webapp (note: there are two apps in this place, choose maven-archetype-webapp), next
-
As shown in the figure below, the next step is to fill in the groupId and archetypeId, and click next.
GroupID actually corresponds to the structure of the JAVA package, which is the directory structure of java in the main directory. ArtifactID is the unique identifier of the project, and the actual name of the corresponding project is the name of the project root directory.
-
As shown in the figure below, in this step, you can directly follow the default and click next, but it may download some things after the creation is completed, which will lead to slowness, so I personally recommend it. First configure the maven path and then click the plus sign on the right
-
Enter the corresponding name and value, then click OK. Click Next. archetypeCatalog represents the archetype metadata used by the plugin. If this parameter is not added, the default is remote, local, which is the central warehouse archetype metadata. Because the central warehouse has too many archetypes, it is very slow. Specify internal to indicate that only internal metadata is used. .
-
As shown in the figure below, fill in the project name and module name, and select the path where the project is located.
The module name is the same as the project name by default, but if there is only one module in the project, it doesn't matter if it is not changed. If there are many modules, it must be modified. finish.
-
As shown in the figure below, don't worry, wait a moment, until the directory structure becomes the structure shown in the figure, indicating that the project is created.
After the project is created, it may not be able to run. It depends on whether tomcat and jdk are configured. See step 2 for details.
END
Second, configure Tomcat
-
Open ProjectStructure on the main page, click the button shown in the figure or press the shortcut key of ctrl+shift+alt+s.
-
After opening ProjectStructure, click Facets->+ sign in turn as shown in the figure, and select Web in the pop-up dialog box.
-
In the pop-up dialog box, select the Maven project (MavenDemo) you just created, and click ok.
-
Then the structure shown in the figure will appear, click the plus sign on the right side of the Deployment Descriptors dialog box, a small dialog box will pop up, select the path where web.xml is located, and click Ok.
-
Click the plus sign on the right side of the Web Resource Directories dialog box again, a small dialog box will pop up, select the path where the webapp is located, and click Ok.
-
再次回到Project Structure,点击左侧 Artifacts,依次点击+号->Web Application:Exploded->From Modules.
-
在弹出的框中选择刚才创建的Maven项目(MavenDemo),Ok.
-
出现下图的对话框,点击Ok即可。
-
接下来开始配置Tomcat。然后在右上角点击那个下拉框,再点击Edit Configurations
-
在弹出的对话框中点击+号,找到Tomcat Server ,选择Local.
-
在弹出的对话框中,选择Deployment,点击右侧的+号,选择Artifact。
-
接着回到Server选项卡,配置一下Tomcat的基本参数,最后点击Ok即可
-
最后点击工具栏上的小虫子按钮,以Debug方式启动Tomcat服务器。
-
如果看到下图的页面,恭喜你,Maven项目的创建及运行已经成功。
END
三、创建Java文件目录
-
创建及部署完Maven项目会发现,main目录下没有java源文件夹。接下来我会教大家怎么创建这个java源文件夹。
-
在主页面打开ProjectStructure,点击图示的按钮或是按ctrl+shift+alt+s快捷键
-
在弹出的Project Structure窗口中,依次从左侧选择Modules->MavenDemo->Sources,打开项目的main目录,在main上单击右键选择New Folder,在弹出的对话框中填写文件的名字后,点击Ok。
-
然后选中刚才创建的文件夹,点击上面的 Mark as: 中的sources按钮,该文件夹就会变成蓝色用于保存java代码,之后点击OK,
-
Finally, the source folder of the java code will appear under the main folder of the main page.
END