码迷,mamicode.com
首页 > 其他好文 > 详细

Maven入门知识介绍

时间:2018-02-20 00:23:21      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:post   enc   目录   项目管理   blog   http   lease   release   pac   

1.1 Maven简介

  Apache Maven 是一个软件项目管理工具。基于项目对象模型的概念,Maven可用来管理项目的依赖、编译、文档 等信息。

  使用maven管理项目时,项目的依赖的jar包将不在包含在项目内,而是集中放置在用户目录的.m2文件下。

1.2 maven安装(请参考网上)

2.1 maven的pom.xml

  maven 是基于项目对象模型的概念运作的,所以maven的项目都有一个pom.xml用来管理项目的依赖以及项目的编译等功能。

  在项目中,我们主要关注下面的元素

  1.denpendencies

  <dependencies></dependencies>,该元素包含多个项目的依赖需要使用<dependency></dependency>。

  2.dependecy

  <dependency></dependency>内部通过groupId、artifactId以及version确定唯一的依赖,有朋友称这三个为坐标,代码如下。

    groupId:组织的唯一标识。

    artifactId:项目的唯一标识。

    version:项目的版本号。

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
           <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
           <version>3.2.6.RELEASE</version>
    </dependency>

3 变量定义

  变量定义:<properties></properties>可定义变量在dependency中引用,代码如下。

<properties>
      <junit.test>3.8.1</junit.test>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.test}</version>
      <scope>test</scope>
    </dependency>
    </dependencies>

4 编译插件

 <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugins</artifactId>
              <version>2.3.2</version>
              <configuration>
                  <source>1.7</source>
                  <target>1.7</target>
              </configuration>
          </plugin>
      </plugins>
    
  </build>

5 maven运作方式

  Maven会自动根据dependency中的依赖配置,直接通过互联网在Maven中心库下载相关依赖包到.m2目录下,.m2目录下是我们的本地Maven库。如果不知道所依赖的jar包的dependency怎么写,可以到http://mvnrepository.com网站检索。

  若Maven中心库中没有你需要的jar包,你需要通过下面的Maven命令打到本地的Maven库后应用即可

mvn install:install-file -DgroupId=com.oracle "DaritifactId=ojdbc14" 
"Dversion=10.2.0.2.0" "Dpackaging=jar" "Dfile=D:\ojdbc4.jar"

 

Maven入门知识介绍

标签:post   enc   目录   项目管理   blog   http   lease   release   pac   

原文地址:https://www.cnblogs.com/zhikou/p/8454683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!