Maven项目管理工具

Maven的简介

  1. 什么是maven

 

是Apache下的一个开源的项目,是纯java编写,并且只是用来管理java项目。

  1. Maven的好处:

传统做法的项目:

uploading.4e448015.gif正在上传…重新上传取消

 

Maven改造后项目

uploading.4e448015.gif正在上传…重新上传取消

分析:

uploading.4e448015.gif正在上传…重新上传取消

2.1综上,maven项目节省空间

2.2一键构建

可以用一个命令(tomcat:run)让项目运行起来

 

2.3可以跨平台

 

2.4应用于大型项目时可以提高开发效率

uploading.4e448015.gif正在上传…重新上传取消

  • Maven的安装配置
  1. 下载安装

从此处

uploading.4e448015.gif正在上传…重新上传取消

把压缩包拷贝到一个没有中文没有空格的目录中,直接解压到当前目录

 

Maven软件的结构

uploading.4e448015.gif正在上传…重新上传取消

 

Maven的核心配置文件

uploading.4e448015.gif正在上传…重新上传取消

  1. 配置:

2.1准备本地仓库

uploading.4e448015.gif正在上传…重新上传取消

把压缩包拷贝到一个没有中文没有空格的目录中,直接解压到当前目录

2.2配置本地仓库

uploading.4e448015.gif正在上传…重新上传取消

2.3配置环境变量

uploading.4e448015.gif正在上传…重新上传取消

 

加到path中

uploading.4e448015.gif正在上传…重新上传取消

2.4验证maven环境是否配置成功

执行mvn -v命令

看到如下界面表示成功:

 

uploading.4e448015.gif正在上传…重新上传取消

 

注意:maven3.3.9版本需要jdk1.7+以上的版本

 

  1. maven的三种仓库(重点)

uploading.4e448015.gif正在上传…重新上传取消

  • 演示入门程序
  1. maven工程目录结构

 

uploading.4e448015.gif正在上传…重新上传取消

uploading.4e448015.gif正在上传…重新上传取消

  1. 演示命令

进入到工程中

uploading.4e448015.gif正在上传…重新上传取消

编译: mvn compile

uploading.4e448015.gif正在上传…重新上传取消

测试: mvn test

uploading.4e448015.gif正在上传…重新上传取消

打包:package

uploading.4e448015.gif正在上传…重新上传取消

打包到本地仓库中 install

 

  1. Maven的生命周期(了解)

Compile   test   package  install  deploy

 

声明周期是由每个阶段组成

3.1Clean生命周期

 

Clean

uploading.4e448015.gif正在上传…重新上传取消

3.2Default生命周期

Compile   test   package  install  deploy

3.3Site生命周期

uploading.4e448015.gif正在上传…重新上传取消

  1. 各个生命周期的关系

不同的生命周期命令可以同时执行  

Mvn clean package    mvn package clean

Mvn test package

  • 构建入门程序

配置插件  m2e

uploading.4e448015.gif正在上传…重新上传取消

 

uploading.4e448015.gif正在上传…重新上传取消

 

创建maven工程

  1. 创建maven project

uploading.4e448015.gif正在上传…重新上传取消

  1. 跳过骨架

uploading.4e448015.gif正在上传…重新上传取消

 

  1. 填写坐标 GAV   (重点)

GroupIp公司或组织域名的倒序

ArtifactID:项目或者模块名 crm 

Version:版本 0.0.1-SNAPSHOT   RELEASE

uploading.4e448015.gif正在上传…重新上传取消

  1. 创建工程

uploading.4e448015.gif正在上传…重新上传取消

  1. 处理红色叉号

出现的原因是因为 web项目没有web.xml文件

解决的方式:

手动在webapp文件夹下创建一个WEB-INF文件夹,在里面放一个web.xml文件

uploading.4e448015.gif正在上传…重新上传取消

  1. 处理编译版本

 

在pom.xml中添加如下代码

 

<build>

                   <!-- 配置了很多插件 -->

                   <plugins>

                            <plugin>

                                     <groupId>org.apache.maven.plugins</groupId>

                                     <artifactId>maven-compiler-plugin</artifactId>

                                     <version>3.5.1</version> 

                                     <configuration>

                                               <source>1.7</source>

                                               <target>1.7</target>

                                               <encoding>UTF-8</encoding>

                                     </configuration>

                            </plugin>

                   </plugins>

         </build>

 

  1. 创建一个servlet

在pom中添加如下代码:

 

<dependencies>

                   <dependency>

                            <groupId>junit</groupId>

                            <artifactId>junit</artifactId>

                            <version>4.9</version>

                            <scope>test</scope>

                   </dependency>

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>servlet-api</artifactId>

                            <version>2.5</version>

                            <scope>provided</scope>

                   </dependency>

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>jsp-api</artifactId>

                            <version>2.0</version>

                            <scope>provided</scope>

                   </dependency>

                  

         </dependencies>

会发现jar包已添加到项目中

uploading.4e448015.gif正在上传…重新上传取消

Servlet代码如下

uploading.4e448015.gif正在上传…重新上传取消

在webapp中新建jsp页面

(略)

  1. 启动项目

右击项目->run as –>maven build..

  • 依赖管理,目标-整合Struts2

 

依赖管理就是对Jar包的管理

 

需求:整合struts2   findById?custId=1

  1. 添加依赖: (重点)

打开maven仓库的视图:

 

uploading.4e448015.gif正在上传…重新上传取消

  1. 重建索引

uploading.4e448015.gif正在上传…重新上传取消

 

 

  1. 创建maven项目(同上)
  2. 跳过骨架(同上)
  3. 填写坐标信息(同上)
  4. 添加web.xml文件(同上)
  5. 修改编译版本(同上)
  6. 添加坐标 选择Dependencies标签 点击add

uploading.4e448015.gif正在上传…重新上传取消

  1. 手动输入要添加的坐标,选择版本

uploading.4e448015.gif正在上传…重新上传取消

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

uploading.4e448015.gif正在上传…重新上传取消

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

 

  1. 写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;

         }

        

}

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

uploading.4e448015.gif正在上传…重新上传取消

内容:

<?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>

 

  1. 添加jsp页面

uploading.4e448015.gif正在上传…重新上传取消

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>

  1. 依赖范围 scope(理解)

Compile

举例:struts2-core-2.3.24.jar

编译时:需要

测试(test命令):需要

打包:需要

运行:需要

Provided

举例:servlet-api。Jar     (重点)

编译时:需要

测试(test命令):需要

打包:不需要

运行:需要

Test

举例:  junit.jar

编译时:不需要

测试(test命令):需要

打包:不需要

运行:不需要

Runtime 

举例:数据库驱动包

编译时:不需要

测试(test命令):需要

打包:需要

运行:需要

 

 

  • 运行调试

 

Github      git

 

  • 总结

uploading.4e448015.gif正在上传…重新上传取消

  • 常见问题

使用命令时如果出现如下错误信息,需要重新安装jdk

uploading.4e448015.gif正在上传…重新上传取消

 

  1. 回顾
    1. Maven的好处
  1. 节省空间
  2. 一键构建
  3. 跨平台
  4. 大型项目提高开发效率
    1. Maven安装部署配置

Maven  3.3.9   jdk 1.7+

    1. Maven的仓库

本地仓库

远程仓库  私服

中央仓库

    1. 常见命令

clean

compile  test  package  install  deploy

site

    1. 添加依赖

对jar的管理

创建索引

    1. 项目构建

 

    1. 依赖范围

compile  provided      test   runtime

  1. 整合ssh框架
    1. 依赖传递

只添加了一个struts2-core依赖,发现项目中出现了很多jar,

这种情况 叫 依赖传递

 

uploading.4e448015.gif正在上传…重新上传取消

 

 

 

依赖范围对依赖传递造成的影响(了解)

uploading.4e448015.gif正在上传…重新上传取消

 

    1. 依赖版本冲突的解决
  1. 第一声明优先原则

 

<dependencies>

  <!--   spring-beans-4.2.4 -->

       <dependency>

                 <groupId>org.springframework</groupId>

                 <artifactId>spring-context</artifactId>

                 <version>4.2.4.RELEASE</version>

       </dependency>

 

 

<!--   spring-beans-3.0.5 -->

       <dependency>

                 <groupId>org.apache.struts</groupId>

                 <artifactId>struts2-spring-plugin</artifactId>

                 <version>2.3.24</version>

       </dependency>

 

  1. 路径近者优先原则

自己添加jar包

 

         <dependency>

                 <groupId>org.springframework</groupId>

                 <artifactId>spring-beans</artifactId>

                 <version>4.2.4.RELEASE</version>

       </dependency>

 

  1. 排除原则

 

       <dependency>

                 <groupId>org.apache.struts</groupId>

                 <artifactId>struts2-spring-plugin</artifactId>

                 <version>2.3.24</version>

                 <exclusions>

                   <exclusion>

                     <groupId>org.springframework</groupId>

                     <artifactId>spring-beans</artifactId>

                   </exclusion>

                 </exclusions>

       </dependency>

 

  1. 版本锁定原则

 

<properties>

                   <spring.version>4.2.4.RELEASE</spring.version>

                   <hibernate.version>5.0.7.Final</hibernate.version>

                   <struts.version>2.3.24</struts.version>

         </properties>

 

         <!-- 锁定版本,struts2-2.3.24、spring4.2.4、hibernate5.0.7 -->

         <dependencyManagement>

                   <dependencies>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-context</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

</dependencies>

</dependencyManagement>

 

 

需求:

传客户ID 页面上显示客户信息

准备数据库

    1. 构建项目

 

  1. 创建数据库

 uploading.4e448015.gif正在上传…重新上传取消

 

  1. 执行准备好的sql脚本

Sql脚本的位置:

 

uploading.4e448015.gif正在上传…重新上传取消

 

 

  1. 完善pom.xml文件,把ssh相关的依赖都添加上去

  <!-- 属性 -->

         <properties>

                   <spring.version>4.2.4.RELEASE</spring.version>

                   <hibernate.version>5.0.7.Final</hibernate.version>

                   <struts.version>2.3.24</struts.version>

         </properties>

 

         <!-- 锁定版本,struts2-2.3.24、spring4.2.4、hibernate5.0.7 -->

         <dependencyManagement>

                   <dependencies>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-context</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-aspects</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-orm</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-test</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-web</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.hibernate</groupId>

                                     <artifactId>hibernate-core</artifactId>

                                     <version>${hibernate.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.apache.struts</groupId>

                                     <artifactId>struts2-core</artifactId>

                                     <version>${struts.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.apache.struts</groupId>

                                     <artifactId>struts2-spring-plugin</artifactId>

                                     <version>${struts.version}</version>

                            </dependency>

                   </dependencies>

         </dependencyManagement>

         <!-- 依赖管理 -->

         <dependencies>

                   <!-- spring -->

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-context</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-aspects</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-orm</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-test</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-web</artifactId>

                   </dependency>

                   <!-- hibernate -->

                   <dependency>

                            <groupId>org.hibernate</groupId>

                            <artifactId>hibernate-core</artifactId>

                   </dependency>

 

                   <!-- 数据库驱动 -->

                   <dependency>

                            <groupId>mysql</groupId>

                            <artifactId>mysql-connector-java</artifactId>

                            <version>5.1.6</version>

                            <scope>runtime</scope>

                   </dependency>

                   <!-- c3p0 -->

 

                   <dependency>

                            <groupId>c3p0</groupId>

                            <artifactId>c3p0</artifactId>

                            <version>0.9.1.2</version>

                   </dependency>

 

 

                   <!-- 导入 struts2 -->

                   <dependency>

                            <groupId>org.apache.struts</groupId>

                            <artifactId>struts2-core</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.apache.struts</groupId>

                            <artifactId>struts2-spring-plugin</artifactId>

                   </dependency>

 

                   <!-- servlet jsp -->

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>servlet-api</artifactId>

                            <version>2.5</version>

                            <scope>provided</scope>

                   </dependency>

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>jsp-api</artifactId>

                            <version>2.0</version>

                            <scope>provided</scope>

                   </dependency>

                   <!-- 日志 -->

                   <dependency>

                            <groupId>org.slf4j</groupId>

                            <artifactId>slf4j-log4j12</artifactId>

                            <version>1.7.2</version>

                   </dependency>

                   <!-- junit -->

                   <dependency>

                            <groupId>junit</groupId>

                            <artifactId>junit</artifactId>

                            <version>4.9</version>

                            <scope>test</scope>

                   </dependency>

                   <!-- jstl -->

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>jstl</artifactId>

                            <version>1.2</version>

                   </dependency>

         </dependencies>

 

         <build>

                   <plugins>

                            <!-- 设置编译版本为1.7 -->

                            <plugin>

                                     <groupId>org.apache.maven.plugins</groupId>

                                     <artifactId>maven-compiler-plugin</artifactId>

                                     <configuration>

                                               <source>1.7</source>

                                               <target>1.7</target>

                                               <encoding>UTF-8</encoding>

                                     </configuration>

                            </plugin>

 

                            <!-- maven内置 的tomcat6插件 -->

                            <plugin>

                                     <groupId>org.codehaus.mojo</groupId>

                                     <artifactId>tomcat-maven-plugin</artifactId>

                                     <version>1.1</version>

                                     <configuration>

                                               <!-- 可以灵活配置工程路径 -->

                                               <path>/ssh</path>

                                               <!-- 可以灵活配置端口号 -->

                                               <port>8080</port>

                                     </configuration>

                            </plugin>

                   </plugins>

         </build>

 

  1. 完成实体类代码

uploading.4e448015.gif正在上传…重新上传取消

 

  1. 完成dao代码

接口

package cn.itcast.dao;

 

import cn.itcast.entity.Customer;

 

public interface CustomerDao {

        

         public Customer getById(Long id);

 

}

实现类

package com.itcast.dao.impl;

import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import cn.itcast.dao.CustomerDao;

import cn.itcast.entity.Customer;

public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao {

         @Override

         public Customer getById(Long id) {

                   return this.getHibernateTemplate().get(Customer.class, id);

         }

}

 

 

  1. 完成service代码

接口

package com.itcast.service;

import cn.itcast.entity.Customer;

public interface CustomerService {

         public Customer getById(Long id);

}

 

实现类

package com.itcast.service.impl;

 

import com.itcast.service.CustomerService;

 

import cn.itcast.dao.CustomerDao;

import cn.itcast.entity.Customer;

 

public class CustomerServiceImpl implements CustomerService {

         private CustomerDao  customerDao;

         public void setCustomerDao(CustomerDao customerDao) {

                   this.customerDao = customerDao;

         }

         @Override

         public Customer getById(Long id) {

                   return customerDao.getById(id);

         }

}

 

  1. 完成action代码

package cn.itcast.action;

import com.itcast.service.CustomerService;

import com.opensymphony.xwork2.ActionSupport;

import cn.itcast.entity.Customer;

public class CutomerAction extends ActionSupport {

         //两个成员变量

         private Customer  customer;

        

         private Long custId;

         public Customer getCustomer() {

                   return customer;

         }

         public void setCustomer(Customer customer) {

                   this.customer = customer;

         }

         private CustomerService customerService;

         public void setCustomerService(CustomerService customerService) {

                   this.customerService = customerService;

         }

         public Long getCustId() {

                   return custId;

         }

         public void setCustId(Long custId) {

                   this.custId = custId;

         }

         public String findById(){

                   customer = customerService.getById(custId);

                   return SUCCESS;

         }

}

 

  1. 拷贝配置文件并修改

从如下图位置拿到配置文件

uploading.4e448015.gif正在上传…重新上传取消

放入到 src/main/resources目录中

uploading.4e448015.gif正在上传…重新上传取消

 

修改内容 略

 

  1. 修改web.xml 添加spring的监听

 

<listener>

 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext.xml</param-value>

</context-param>       

 

  1. 运行项目

 

  1. 分模块开发

父工程来管理   聚合

 

    1. 创建父工程:

1、

uploading.4e448015.gif正在上传…重新上传取消

2、创建出的父工程如下

uploading.4e448015.gif正在上传…重新上传取消

3、在pom.Xml中添加以下信息:

 

  <!-- 属性 -->

         <properties>

                   <spring.version>4.2.4.RELEASE</spring.version>

                   <hibernate.version>5.0.7.Final</hibernate.version>

                   <struts.version>2.3.24</struts.version>

         </properties>

 

         <!-- 锁定版本,struts2-2.3.24、spring4.2.4、hibernate5.0.7 -->

         <dependencyManagement>

                   <dependencies>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-context</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-aspects</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-orm</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-test</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-web</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.hibernate</groupId>

                                     <artifactId>hibernate-core</artifactId>

                                     <version>${hibernate.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.apache.struts</groupId>

                                     <artifactId>struts2-core</artifactId>

                                     <version>${struts.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.apache.struts</groupId>

                                     <artifactId>struts2-spring-plugin</artifactId>

                                     <version>${struts.version}</version>

                            </dependency>

                   </dependencies>

         </dependencyManagement>

         <!-- 依赖管理 -->

         <dependencies>

                   <!-- spring -->

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-context</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-aspects</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-orm</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-test</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-web</artifactId>

                   </dependency>

                   <!-- hibernate -->

                   <dependency>

                            <groupId>org.hibernate</groupId>

                            <artifactId>hibernate-core</artifactId>

                   </dependency>

 

                   <!-- 数据库驱动 -->

                   <dependency>

                            <groupId>mysql</groupId>

                            <artifactId>mysql-connector-java</artifactId>

                            <version>5.1.6</version>

                            <scope>runtime</scope>

                   </dependency>

                   <!-- c3p0 -->

 

                   <dependency>

                            <groupId>c3p0</groupId>

                            <artifactId>c3p0</artifactId>

                            <version>0.9.1.2</version>

                   </dependency>

 

 

                   <!-- 导入 struts2 -->

                   <dependency>

                            <groupId>org.apache.struts</groupId>

                            <artifactId>struts2-core</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.apache.struts</groupId>

                            <artifactId>struts2-spring-plugin</artifactId>

                   </dependency>

 

                   <!-- servlet jsp -->

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>servlet-api</artifactId>

                            <version>2.5</version>

                            <scope>provided</scope>

                   </dependency>

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>jsp-api</artifactId>

                            <version>2.0</version>

                            <scope>provided</scope>

                   </dependency>

                   <!-- 日志 -->

                   <dependency>

                            <groupId>org.slf4j</groupId>

                            <artifactId>slf4j-log4j12</artifactId>

                            <version>1.7.2</version>

                   </dependency>

                   <!-- junit -->

                   <dependency>

                            <groupId>junit</groupId>

                            <artifactId>junit</artifactId>

                            <version>4.9</version>

                            <scope>test</scope>

                   </dependency>

                   <!-- jstl -->

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>jstl</artifactId>

                            <version>1.2</version>

                   </dependency>

         </dependencies>

 

         <build>

                   <plugins>

                            <!-- 设置编译版本为1.7 -->

                            <plugin>

                                     <groupId>org.apache.maven.plugins</groupId>

                                     <artifactId>maven-compiler-plugin</artifactId>

                                     <configuration>

                                               <source>1.7</source>

                                               <target>1.7</target>

                                               <encoding>UTF-8</encoding>

                                     </configuration>

                            </plugin>

 

                            <!-- maven内置 的tomcat6插件 -->

                            <plugin>

                                     <groupId>org.codehaus.mojo</groupId>

                                     <artifactId>tomcat-maven-plugin</artifactId>

                                     <version>1.1</version>

                                     <configuration>

                                               <!-- 可以灵活配置工程路径 -->

                                               <path>/ssh</path>

                                               <!-- 可以灵活配置端口号 -->

                                               <port>8080</port>

                                     </configuration>

                            </plugin>

 

                   </plugins>

         </build>

 

4、发布到本地仓库

执行install命令

 

 

    1. 创建dao子模块

1、在ssh-parent项目上右击 ,创建时选择 Maven Module

uploading.4e448015.gif正在上传…重新上传取消

2、填写子模块名称ssh-dao

uploading.4e448015.gif正在上传…重新上传取消

3、把属于dao的代码拷贝到 该模块中:

uploading.4e448015.gif正在上传…重新上传取消

4、完成后发布到本地仓库中

 

    1. 创建service子模块

1、创建方式如上:

2、把属于service的代码拷贝到该工程中

uploading.4e448015.gif正在上传…重新上传取消

3、发布到本地仓库中

 

    1. 创建Action子模块

1、选择war的打包方式

uploading.4e448015.gif正在上传…重新上传取消

  1. 拷贝属于action的代码和配置文件

uploading.4e448015.gif正在上传…重新上传取消

  1. 修改web.xml  添加spring监听

 

<listener>

 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

        

<context-param>

 <param-name>contextConfigLocation</param-name>

 <param-value>classpath*:applicationContext-*.xml</param-value>

</context-param>

 

 

4、添加页面:

uploading.4e448015.gif正在上传…重新上传取消

 

 

 

  1. 私服 nexus

安装nexus

uploading.4e448015.gif正在上传…重新上传取消

启动服务

uploading.4e448015.gif正在上传…重新上传取消 

启动失败的解决方法:

 

uploading.4e448015.gif正在上传…重新上传取消

uploading.4e448015.gif正在上传…重新上传取消

 

 

登录nexus

用户名/密码  admin/admin123

 

 

仓库类型

uploading.4e448015.gif正在上传…重新上传取消

 

Virtual   虚拟仓库

Proxy  代理仓库

Hosted  宿主仓库  本地仓库

Group 组

需求:

把dao放到私服上,然后service从私服上下载

 

 

需求 :将ssh_dao的这个工程打成jar包,并放入到私服上去.

    1. 上传dao

第一步: 需要在客户端即部署dao工程的电脑上配置 maven环境,并修改 settings.xml 文件,配置连接私服的用户和密码 。

 

此用户名和密码用于私服校验,因为私服需要知道上传都 的账号和密码 是否和私服中的账号和密码 一致。

 

    <server>

      <id>releases</id>

      <username>admin</username>

      <password>admin123</password>

    </server>

         <server>

      <id>snapshots</id>

      <username>admin</username>

      <password>admin123</password>

    </server>

 

第二步: 配置项目pom.xml

 

配置私服仓库的地址,本公司的自己的jar包会上传到私服的宿主仓库,根据工程的版本号决定上传到哪个宿主仓库,如果版本为release则上传到私服的release仓库,如果版本为snapshot则上传到私服的snapshot仓库

 

  <distributionManagement>

    <repository>

        <id>releases</id>

    <url>http://localhost:8081/nexus/content/repositories/releases/</url>

    </repository>

    <snapshotRepository>

        <id>snapshots</id>

    <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>

    </snapshotRepository>

  </distributionManagement>

 

注意:pom.xml这里<id> 和 settings.xml 配置 <id> 对应!

 

第三步:执行deploy命令发布到私服

 

 

 

    1. 下载dao

第一步 修改settings.xml

<profile>  

         <!--profile的id-->

    <id>dev</id>  

    <repositories>  

      <repository> 

                   <!--仓库id,repositories可以配置多个仓库,保证id不重复-->

        <id>nexus</id>  

                   <!--仓库地址,即nexus仓库组的地址-->

        <url>http://localhost:8081/nexus/content/groups/public/</url>  

                   <!--是否下载releases构件-->

        <releases>  

          <enabled>true</enabled>  

        </releases>  

                   <!--是否下载snapshots构件-->

        <snapshots>  

          <enabled>true</enabled>  

        </snapshots>  

      </repository>  

    </repositories> 

          <pluginRepositories> 

    <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->

        <pluginRepository> 

           <!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->

            <id>public</id> 

            <name>Public Repositories</name> 

            <url>http://localhost:8081/nexus/content/groups/public/</url> 

        </pluginRepository> 

    </pluginRepositories> 

  </profile> 

 

 

  <activeProfiles>

    <activeProfile>dev</activeProfile>

  </activeProfiles>

 

第二步 删除本地仓库中的dao

 

第三步 update service工程,出现以下信息说明已经成功

uploading.4e448015.gif正在上传…重新上传取消

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值