maven学习记录二——依赖管理

5       依赖管理

Jar包的管理

需求:整合struts2   页面上传一个客户id 跳转页面

5.1     添加依赖:

打开maven仓库的视图:

 

5.2     重建索引

 

1、  创建maven项目(同上)

2、  跳过骨架(同上)

3、  填写坐标信息(同上)

4、  添加web.xml文件(同上)

5、  修改编译版本(同上)

6、  添加坐标 选择Dependencies标签 点击add

 

7、  手动输入要添加的坐标,选择版本

 

8、  可以看到 pom.xml文件中多出了如下代码

9、  同样的方式添加servlet-api.jar和jsp-api.jar 注意选择scope为provided

10、              写action代码

import com.opensymphony.xwork2.ActionSupport;

public class CutomerAction extends ActionSupport {
         private Long custId;
         public Long getCustId() {
                   return custId;

         }
         public void setCustId(Long custId) {

                   this.custId = custId;
         }
         public String findById(){
                   return SUCCESS;

         }
}

11、              添加struts.xml文件放到resources目录中

 

内容:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

    "http://struts.apache.org/dtds/struts-2.3.dtd">

 

<struts>

         <!-- 配置常量 -->

         <!-- 字符集 -->

         <constant name="struts.i18n.encoding" value="UTF-8"></constant>

         <!-- 开发模式 -->

         <constant name="struts.devMode" value="true"></constant>

 

         <!-- 通用package -->

         <package name="customer" namespace="/" extends="struts-default">

 

                   <action name="find" class="cn.itcast.action.CutomerAction"   

                            method="findById">

                            <result name="success">/jsp/info.jsp</result>

                   </action>

 

         </package>

</struts>

12、              添加jsp页面

 

15、修改web.xml文件 添加过滤器

<filter>

    <filter-name>struts2</filter-name>

     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

  </filter>

  <filter-mapping>

  <filter-name>struts2</filter-name>

  <url-pattern>/*</url-pattern>

  </filter-mapping>

5.3     依赖范围

5.3.1  Compile  struts2-core

编译(compile)时需要 测试时需要,,运行时需要,打包时需要

5.3.2  Provided  jsp-api.jar   servlet-api.jar

编译(compile)时需要,测试(test)时也需要 ,运行时不需要,打包时不需要

5.3.3  Runtime   数据库驱动包

编译时不需要,测试时需要,,运行时需要,打包时需要

5.3.4  Test  junit.jar

编译时不需要,测试时需要,运行时不需要,打包也不需要

添加插件

 

Maven  add  plugin

 

如果用tomcat7运行用命令:

Tomcat7:run

常见问题:

 

这是jdk安装的有问题,从新安装配置即可。

原文地址:https://www.cnblogs.com/PengChengLi/p/8506070.html