maven学习

来源:互联网 发布:香港翡翠台直播软件 编辑:程序博客网 时间:2024/06/08 03:54
Tale Blog

编辑文章

java  x
  • JavaWeb
切换为Markdown编辑器
  1. 环境配置
    从maven官网下载压缩包并解压到电脑中,配置系统环境变量:
    新建MAVEN_HOME:D:\maven\apache-maven-3.5.0



    配置系统变量Path:%MAVEN_HOME%\bin;





  2. 检测maven是否配置成功





  3. 设置maven本地仓库存储地址





  4. 在eclipse中配置maven







  5. 在eclipse中用maven构建第一个wab项目




  6. 给maven项目添加jdk插件及tomcat插件.,在pom.xml中配置
  1. <!-- 添加项目jdk编译插件 --><build><plugins><!-- 编译版本设为1.8 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat7-maven-plugin</artifactId><version>2.2</version><configuration><uriEncoding>UTF-8</uriEncoding><port>8080</port><path>1maven</path></configuration></plugin></plugins></build>


添加这些代码之后,选中项目 Maven --> update project..跟新jdk和tomcat为自己设点的版本

    7.添加测试类sevlet(直接用servlet工具,其会自动在web.xml中配置)
        
    解决方法:添加对应的jar包
        

    修改servlet中代码:

    package com.ctgu;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class HelloMaven extends HttpServlet {private static final long serialVersionUID = 1L;    public HelloMaven() {    }protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType("text/html;charset=utf-8");response.getWriter().write("hello world");}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doGet(request, response);}}
    8.运行maven项目 Run --> Maven build...
    

    9.运行成功并访问
            

    
        

    

        

开启
关闭
开启
关闭
开启
关闭
开启
关闭
返回列表  
2017 © Tale.