IntelliJ IDEA 15 创建maven项目

我这里安装的是

IntelliJ IDEA 2018.3.4 x64  

tomcat  apache-tomcat-9.0.12

maven 3.6.0

IntelliJ IDEA 15 创建maven项目_第1张图片

点击createNew project

 

IntelliJ IDEA 15 创建maven项目_第2张图片

选择Maven  点击Next

 

IntelliJ IDEA 15 创建maven项目_第3张图片

 

GroupId(一般填公司名) 和ArtifactId  随便填写也可填写一致的名称也可,继续点击Next

IntelliJ IDEA 15 创建maven项目_第4张图片

 

点击Finish,之后稍等片刻,即可看到项目创建目录

IntelliJ IDEA 15 创建maven项目_第5张图片

 

因为在开始创建过程中没有选择用骨架创建,所以才会出来上面这种目录结构

接下来就开始创建web项目了

右键点击Maven_text目录,出现Add Framework Support,点击这个

IntelliJ IDEA 15 创建maven项目_第6张图片

勾选 Web Application,点击OK

IntelliJ IDEA 15 创建maven项目_第7张图片

点击之后就能在项目里面看到web文件夹

IntelliJ IDEA 15 创建maven项目_第8张图片

之后先配置好pom.xml下的web项目依赖包:

在pom.xml中添加如下代码

   <dependencies>
    <dependency>
        <groupId>javax.servletgroupId>
        <artifactId>servlet-apiartifactId>
        <version>3.0-alpha-1version>
    dependency>
        <dependency>
            <groupId>javax.servlet.jspgroupId>
            <artifactId>jsp-apiartifactId>
            <version>2.2version>
        dependency>
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>jstlartifactId>
            <version>1.2version>
        dependency>
        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>3.8.1version>
        dependency>
    dependencies>

 

写好之后点击 下面蓝色的字 Enable Auto-Import

IntelliJ IDEA 15 创建maven项目_第9张图片

这个时候你就能在右边看到自动加载的Maven包了

IntelliJ IDEA 15 创建maven项目_第10张图片

 

然后在src/main/java/目录下新建一个servlet

IntelliJ IDEA 15 创建maven项目_第11张图片

Name任意起个test_Servlet,点击OK

IntelliJ IDEA 15 创建maven项目_第12张图片

编写test_Serlet.java

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name="test_Servlet")
public class test_Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置网页响应类型
        response.setContentType("text/html");
        //实现具体操作
        PrintWriter out = response.getWriter();
        out.println("This is a test servlet page");
    }
}

编写web.xml


         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    
        test_Servlet
        class>test_Servletclass>
    

    
        test_Servlet
        /test_Servlet
    

IntelliJ IDEA 15 创建maven项目_第13张图片

发现annotation包是红色的,没有导入,不用管它,配置tomcat容器

点击  Add Configuration

IntelliJ IDEA 15 创建maven项目_第14张图片

点击+号,找到最下面的tomcat Server 点击Local

IntelliJ IDEA 15 创建maven项目_第15张图片

 

进行配置,Name随便起

IntelliJ IDEA 15 创建maven项目_第16张图片

 

IntelliJ IDEA 15 创建maven项目_第17张图片

 

进入项目设置里

IntelliJ IDEA 15 创建maven项目_第18张图片

 

点击Moudle点击最右边的+号,点击2,添加tomcat9.0.12,点击OK

或者添加tomcat的jar包也可

IntelliJ IDEA 15 创建maven项目_第19张图片

 

 

 

最后发布运行

IntelliJ IDEA 15 创建maven项目_第20张图片

 

 

这个内容有点单一哈,,更改

IntelliJ IDEA 15 创建maven项目_第21张图片

 

index的内容即可

转载于:https://www.cnblogs.com/Robertzewen/p/10412420.html

你可能感兴趣的:(IntelliJ IDEA 15 创建maven项目)