Idea+maven+tomcat deploys the first tomcat project

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

Tools/Materials

 
  • IntelliJ IDEA 2016.3.4
  • apache-maven-3.3.9
  • apache-tomcat-8.5.11

1. Create a Maven project

 
  1. 1

     As shown below, after opening the idea, file -> new -> project

    IDEA creates a Maven project and deploys it
  2. 2

    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 

    IDEA creates a Maven project and deploys it
  3. 3

    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. 

    IDEA creates a Maven project and deploys it
  4. 4

    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

    IDEA creates a Maven project and deploys it
  5. 5

    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. .

    IDEA creates a Maven project and deploys it
  6. 6

    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. 

    IDEA creates a Maven project and deploys it
  7. 7

    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.

    IDEA creates a Maven project and deploys it
    END

Second, configure Tomcat

 
  1. 1

    Open ProjectStructure on the main page, click the button shown in the figure or press the shortcut key of ctrl+shift+alt+s.

    IDEA creates a Maven project and deploys it
  2. 2

    After opening ProjectStructure, click Facets->+ sign in turn as shown in the figure, and select Web in the pop-up dialog box.

    IDEA creates a Maven project and deploys it
  3. 3

    In the pop-up dialog box, select the Maven project (MavenDemo) you just created, and click ok.

    IDEA creates a Maven project and deploys it
  4. 4

    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.

    IDEA creates a Maven project and deploys it
  5. 5

    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.

    IDEA creates a Maven project and deploys it
  6. 6

    再次回到Project Structure,点击左侧 Artifacts,依次点击+号->Web Application:Exploded->From Modules.

    IDEA creates a Maven project and deploys it
  7. 7

    在弹出的框中选择刚才创建的Maven项目(MavenDemo),Ok.

    IDEA creates a Maven project and deploys it
  8. 8

    出现下图的对话框,点击Ok即可。

    IDEA creates a Maven project and deploys it
  9. 9

    接下来开始配置Tomcat。然后在右上角点击那个下拉框,再点击Edit Configurations

    IDEA creates a Maven project and deploys it
  10. 10

    在弹出的对话框中点击+号,找到Tomcat Server ,选择Local.

    IDEA creates a Maven project and deploys it
  11. 11

    在弹出的对话框中,选择Deployment,点击右侧的+号,选择Artifact。

    IDEA creates a Maven project and deploys it
  12. 12

    接着回到Server选项卡,配置一下Tomcat的基本参数,最后点击Ok即可

    IDEA creates a Maven project and deploys it
  13. 13

    最后点击工具栏上的小虫子按钮,以Debug方式启动Tomcat服务器。

    IDEA creates a Maven project and deploys it
  14. 14

    如果看到下图的页面,恭喜你,Maven项目的创建及运行已经成功。

    IDEA creates a Maven project and deploys it
    END

三、创建Java文件目录

 
  1.  

    创建及部署完Maven项目会发现,main目录下没有java源文件夹。接下来我会教大家怎么创建这个java源文件夹。

    IDEA creates a Maven project and deploys it
  2.  

    在主页面打开ProjectStructure,点击图示的按钮或是按ctrl+shift+alt+s快捷键

    IDEA creates a Maven project and deploys it
  3.  

    在弹出的Project Structure窗口中,依次从左侧选择Modules->MavenDemo->Sources,打开项目的main目录,在main上单击右键选择New Folder,在弹出的对话框中填写文件的名字后,点击Ok。

    IDEA creates a Maven project and deploys it
  4.  

    然后选中刚才创建的文件夹,点击上面的 Mark as: 中的sources按钮,该文件夹就会变成蓝色用于保存java代码,之后点击OK,

    IDEA creates a Maven project and deploys it
  5.  

    Finally, the source folder of the java code will appear under the main folder of the main page.

    IDEA creates a Maven project and deploys it
    END

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325477743&siteId=291194637
Recommended