maven的依赖管理详细

时间:2023-03-10 01:09:50
maven的依赖管理详细

依赖管理

Jar包的管理

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

添加依赖:

打开maven仓库的视图:

maven的依赖管理详细

重建索引

maven的依赖管理详细

1、 创建maven项目(同上)

2、 跳过骨架(同上)

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

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

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

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

maven的依赖管理详细

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

maven的依赖管理详细

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

maven的依赖管理详细

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

10、 写action代码

maven的依赖管理详细
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;
}
}
maven的依赖管理详细

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

maven的依赖管理详细

内容:

maven的依赖管理详细
<?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>
maven的依赖管理详细

12、 添加jsp页面

maven的依赖管理详细

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

maven的依赖管理详细
<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>
maven的依赖管理详细

依赖范围

3.1 Compile  struts2-core

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

3.2 Provided  jsp-api.jar   servlet-api.jar

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

3.3 Runtime   数据库驱动包

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

3.4 Test  junit.jar

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

maven的依赖管理详细

添加插件

  Maven  add  plugin

如果用tomcat7运行用命令:

  Tomcat7:run

常见问题:

maven的依赖管理详细