Gradle简单的Web工程运行demo

0:build.gradle

plugins {
    id 'java'
    /**
     * 打成war包的形式
     */
    id 'war'
}

group 'com.lz.web'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenLocal()
    mavenCentral()
}

/**
 * maven:provided
 * provided:在编译和测试的过程有效,最后生成war包时不会加入,诸如:servlet-api,
 * 因为servlet-api,tomcat等web服务器已经存在了,如果再打包会冲突
 * gradle:provided和compile的区别:
 * 如果你的jar包/依赖代码 仅在编译的时候需要,但是在运行时不需要依赖,就用providedCompile
 * 此属性 替代了maven中的provided
 */
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.springframework', name: 'spring-context', version: '5.0.2.RELEASE'
    compile group: 'org.springframework', name: 'spring-web', version: '5.0.2.RELEASE'
    compile group: 'org.springframework', name: 'spring-webmvc', version: '5.0.2.RELEASE'
    compile group: 'org.springframework', name: 'spring-tx', version: '5.0.2.RELEASE'
    compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'
    compileOnly ('javax.servlet:jsp-api:2.0'){
        exclude group: 'javax.servlet'
    }
    compile group: 'com.alibaba', name: 'fastjson', version: '1.2.54'
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.1'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'
    compile group: 'org.apache.logging.log4j', name: 'log4j-web', version: '2.11.1'
}

1:web.xml



    chinaTelecomLogAnalyzer
    
        index.html
        index.htm
        index.jsp
    

    
    
        contextConfigLocation
        classpath:applicationContext.xml
    

    
    
        org.springframework.web.context.ContextLoaderListener
    

    
    
        log4jConfiguration
        classpath:log4j2.xml
    
    
        org.apache.logging.log4j.web.Log4jServletContextListener
        
    
    
        log4jServletFilter
        org.apache.logging.log4j.web.Log4jServletFilter
    
    
        log4jServletFilter
        /*
        REQUEST
        FORWARD
        INCLUDE
        ERROR
    



    
    
        manager
        org.springframework.web.servlet.DispatcherServlet
        
            springmvc
            contextConfigLocation
            classpath:spring-mvc.xml
        
        1
    
    
        manager
        /
    
    
    
        characterEncodingFilter
        org.springframework.web.filter.CharacterEncodingFilter
        
            encoding
            utf-8
        
    
    
        characterEncodingFilter
        *
    

2:applicationContext.xml




    
    

3:spring-mvc.xml




    
    

    
    

    
        
    
    
        
    
        
        
    

    
    

4:log4j2.xml



    

        
            
            
        
    

    

        
        
            
            
        

        

        
            
            
        

    

5:config.properties空文件 里面没内容

#空的 待添加

6:HelloController

package com.lz.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/toHelloJsp")
    public String toHelloJsp(){
        return "hello";
    }
}

7:hello.jsp

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/12/31
  Time: 22:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


hello jsp!


8:index.jsp

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/12/31
  Time: 22:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title





9:工程目录结构:

Gradle简单的Web工程运行demo_第1张图片

 10:启动工程

Gradle简单的Web工程运行demo_第2张图片

你可能感兴趣的:(gradle)