MAVEN基础知识

 

MAVEN基础知识

 

MAVEN不仅是构建工具,还是一个依赖管理工具和项目信息管理工具

 

POM.XML文件基本配置

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

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>     <!--对于maven2和3只能是4.0.0-->

  <groupId>com.yzjljm</groupId>      <!--定义了项目属于哪个组,一般为域名-->

  <artifactId>name-core<artifactId>    <!--定义当前maven项目唯一ID,一般用项目名称-->

  <version>1.0-SNAPSHOT</version>    <!--版本号-->

  <packaging>jar</packaging>        <!--默认为jar,还可以为pom,war-->

  <name>PROJECT NAME</name>       <!--声明一个对用户更为友好的项目名称-->

  

     <modules>                                               <!--聚合模块,要把packaging设值为pom-->

    <module>xxx-extension</module>

    <module>xxx-core</module>

   </modules>



  <parent>                                                   <!--继承,要把packaging设值为pom-->

    <groupId>xxx</groupId>

    <artifactId></artifactId>

    <version>xxx</version>

    <relativePath>../xxx/pom.xml</relativePath>

  </parent>  





  <properties>
    <springframework.version>2.5.6</springframework.version>   <!--spring版本号统一配置-->
  </properties>

  

 <dependencies>                                      <!--依赖声明-->

    <dependency>                            

      <groupId>junit</groupId>    <!--groupId和artifactId和version定义一个maven项目的坐标-->

      <artifactId>junit</artifactId>

      <version>4.7</version>

      <scope>test</scope>                    <!--依赖范围,只对测试有效-->

    </dependency>

    <dependency>

      <groupId>org.springframework</groupId>

      <artifactId>srping-core</artifactId>

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

      <exclusions>

        <exclusion>        <!--排除传递性依赖-->

          <groupId>xxx</groupId>

          <artifactId>xxx</artifactId>

        </exclusion>

      </exclusions>

    </dependency>

  </dependencies>



  <build>

    <resources>       <resource> <!--编译资源-->         <directory>src/main/java</directory>         <includes>           <includes>**/*.*</includes>         </includes>         <excludes>           <exclude></exclude>         </excludes>       </resource>     </resources>
    
    <testResources> <!--测试资源-->
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
      </testResource>
    </testResources>
    <plugins>       <plugin> <!--插件配置,compiler插件默认只支持java1.3-->         <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-compiler-plugin</artifactId>         <configuration> <!--让插件支持java1.6-->           <source>1.6</source>           <target>1.6</target>         </configuration>       </plugin>       <plugin>         <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-antrun-plugin</artifactId>         <version>1.3</version>         <executions>           <execution>             <id>ant-validate</id> <!--把插件与validate阶段绑定,构成ant-validate任务-->             <phase>validate</phase>             <goals>               <goal>run</goal>             </goals>             <configuration>               <tasks> <!--向控制台输出这句话-->                 <echo>I'm bound to validate phase.</echo>               </tasks>             </configuration>           </execution>         </executions>       <plugin>     </plugins>   </build>   <repositories>     <repository> <!--配置远程仓库,默认配置了central仓库-->       <id>jboss</id>       <name>jboss repository</name>       <url>http://repository.jboss.com/maven2/</url>       <releases>         <enabled>true</enabled>       </releases>       <snapshots>         <enabled>false</enabled>       </snapshots>       <layout>default</layout>     </repository>   </repositoreies>   <pluginRepositories> <!--maven默认插件仓库配置-->     <pluginRepository>       <id>central</id>       <name>Maven Plugin Repository</name>       <url>http://repo1.maven.org/maven2</url>       <layout>default</layout>       <snapshots>         <enabled>false</enabled>       </snapshots>       <releases>         <updatePolicy>never</updatePolicy>       </releases>     </pluginRepository>   <pluginRepositories>   <distributionManagement> <!--配置私服-->     <repository>       <id>proj-releases</id>       <name>PROJ RELEASES REPOSITORY</name>       <url>http://10.1.20.171/content/repositories/proj-release</url>     </repository>     <snapshotRepository>       <id>proj-snapshots</id>       <name>PROJ SNAPSHOT REPOSITORY</name>       <url>http://192.168.1.100/content/repositories/proj-snapshots</url>     </snapshotRepository>   </distributionManagement>   <mirrors>     <mirror>       <id>maven.net.cn</id>       <name>one of the central mirrors in china</name>       <url>http://maven.net.cn/content/groups/public/</url>       <mirrorOf>central</mirrorOf> <!--配置central仓库在中国的镜像-->     </mirror>   </mirrors> </project>

 

settings.xml文件

 

  <localRepository>D:\java\repository</localRepository>     <!--配置本地仓库-->



  <servers>              <!--配置远程仓库认真信息-->

    <server>

      <id>my-prod</id>

      <username>repo-user</username>

      <password>repo-pwd</password>

    </server>

  </servers>

 

 

posted @ 2017-01-09 13:59  Nreo  阅读(200)  评论(0编辑  收藏  举报