如何安装 maven

简述:
maven 是一个项目管理工具。可以帮助我们导入本地仓库的依赖jar包。帮助我们构建项目。
注: 
    1. 当前给出的文件列表仅支持64位机器。
    2. 在所有的配置路劲中不允许出现中文

一.  需要准备的文件列表
1. apache-maven-3.3.9-bin.tar.gz 
2. jdk(1.8.0_60), java运行环境。
3. eclipse-jee.zip
4. repostitory (本地仓库)

二. 配置相关环境
1.  jdk
    我的电脑/此电脑/这台机器/计算机 -> 右键  -> 属性 -> 高级系统设置 ->环境变量 ->【系统变量中】 -> 新建 -> 变量名:JAVA_HOME.  -> 变量值: (JDK安装目录)->确定(3次)

2. 配置 maven. 
    a. 解压缩 apache-maven-3.3.9-bin.tar.gz  . 在解压后的文件目录中. 使用Notepad++ 打开 conf/settings.xml 文件。
    
    b. settings 节点下边有一段注释  localRepository 复制出来作为一个节点。设置本地仓库的路径。
          eg:
             <localRepository>E:/devloper/.m2/repository</localRepository>

            E:/devloper/.m2/repository 是指你以后的jar包存放的位置
            在这里将 repository.zip 解压到  指向的目录中。
        注意: 如何建立有特殊符号的文件夹
      在资源管理器的地址栏输入cmd -> 回车 ,会在控制台打开当前目录。使用mkdir  .m2 命令创建.m2 文件夹。 rmdir 删除文件夹。

   c. settings /  profiles  节点下配置maven项目使用jdk版本
         <profile>
          <id>jdk18</id>
          <activation>
            <jdk>1.8</jdk>
            <activeByDefault>true</activeByDefault>  
          </activation>
          <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
          </properties>
        </profile>
        
  3. 在eclipse中配置maven.
    a. 启动eclipse
    b. 在eclipse 的菜单中点击 Window -> Preferences -> 左侧下方查找 Maven -> Installations -> Add... ->New Maven Runtime. -> 在 Installation home 右侧点击 Directory... 选择刚才解压的 maven 路径。-> Finish . 在Select Installations 选择刚才添加的maven 运行时环境。(最后一个点上勾)。-> Apply.
    c. Preferences 中的 Maven->User Settings . 在右侧的user settings 下方右侧的 Browse... 选择 maven  运行时环境中的conf/settings.xml 文件。 选择之后点击Update Settings 按钮。
    注意: Local Repository 的路径指向 settings.xml 文件中配置的路径后。证明配置成功。


三. 使用eclipse 创建项目。
    1. Package Explore -> 右键 -> New -> maven Project . 弹出 New maven Project 窗体
    2. 点击Next  进入  Select an Archetype 界面。
        a.  选择 quickstart 1.1 会创建一个普通java项目。
        b.  选择 webapp 1.0 会创建一个web项目。
        选择后进入下一步。 
    3. 填入组织编号(Group Id)项目编号(Artifacti Id)
        eg: 
            Group Id > me.youyue.a196
            Artifacti Id > app
    4. 当创建web项目的时候。会出现 The supperclass "javax.servlet.HttpServlet" was not found 的错误。 
        在pom.xml 中配置依赖的jar包。
        在pom.xml 中的  dependencies 节点下边 添加 dependency 节点 
        内容如下:
         <dependency>
               <groupId>junit</groupId>
               <artifactId>junit</artifactId>
               <version>3.8.1</version>
               <scope>test</scope>
        </dependency>
    5. 在pom.xml 文件中配置项目的运行环境。
        build 节点下创建插件管理
         <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
            </plugin>
        </plugins>
      </pluginManagement>
    6.执行项目
       选中项目-> 右键 -> Run as -> Run Configeration  打开Run Configerations 窗体。
        选中maven Build 。 点击左侧上方白色添加按钮(New launch Configeration)。会在右侧展开 Base directory should be specified  面板。 在右侧的BaseDicreatory  选择工作空间中的项目。在 下边的Goals 填入 : tomcat7:run -Dmaven.tomcat.port=80 -> Apply . -> Run .   
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值