Maven使用小结

来源:互联网 发布:制作动态图片的软件 编辑:程序博客网 时间:2024/06/05 14:54

前言:以下对maven的总结,都是基于我在项目中用到的一些知识的总结,对于暂时还没有用到的那部分,打算用到时,再进行总结。

什么是maven

maven是一种项目管理工具,它包括:项目构建,依赖管理,项目信息管理等。在开发android应用时,maven主要帮助我们下载jar包到本地仓库,供所有maven项目使用;而且,它还可以寻找依赖jar包并下载

配置

maven的配置包括两部分:一部分是修改安装目录下的setting.xml,这种修改是全局定制maven的行为,一般情况下,我们复制setting.xml文件到~/.m2/目录下(~/表示用户目录下),在此修改setting.xml文件,是在用户范围内定制maven的行为。另一部分是在maven项目中,都有一个pom.xml文件,我们通过修改pom.xml文件,来定制maven的行为。pom(Project Object Model),项目对象原型。注意:在pom.xml里的配置会覆盖setting.xml里面的。

setting.xml

<?xml version="1.0" encoding="UTF-8"?><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  <!--本地maven仓库的目录-->  <localRepository>E:\Files\maven\apache-maven-3.2.3\repo</localRepository>  <!--是否使用与用户交互模式-->  <interactiveMode>true</interactiveMode>  <!--是否采用离线模式下工作-->    <offline>false</offline>  <pluginGroups>   </pluginGroups>  <!--代理-->  <!--代理服务器是介于浏览器与服务器之间的一种服务器,一般情况下,我们直接使用浏览器去访问服务器;当代理服务器存在时,浏览器会先访问代理服务器,代理服务器上不存在要访问的信息时,再去访问服务器,同时,服务器返回数据时,也是通过代理服务器,再到浏览器。使用代理服务器安全性更高!-->  <proxies>  </proxies>  <!--配置一些认证信息-->  <servers>  </servers>  <!--在网上内容完全相同而且同步更新的两个或多个服务器,除主服务器外,其余的都被称为镜像服务器,目的是为了在主服务器不能服务的时候,不中断服务-->  <!--远程仓库的镜像-->  <mirrors>        <mirror>            <!--标识这个镜像-->            <id>...</id>            <!--谁的镜像-->            <mirrorOf>...</mirrorOf>            <!--镜像的地址-->            <url>http://...</url>        </mirror>        <mirror>            <!--标识这个镜像-->            <id>...</id>            <!--谁的镜像-->            <mirrorOf>...</mirrorOf>            <!--镜像的地址-->            <url>http://...</url>        </mirror>  </mirrors>  <!--配置信息与相关激活条件,默认激活第一个-->  <profiles>        <profile>            <id>id1</id>               </profile>        <profile>            <id>id2</id>               </profile>  </profiles>  <!-- 激活生效的Profiles文件 -->    <activeProfiles>        <activeProfile>id1</activeProfile>    </activeProfiles></settings>

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/maven-v4_0_0.xsd">    <modelVersion>4.0.0</modelVersion>    <groupId>com.xx.xx</groupId>    <artifactId>xx</artifactId>    <version></version>    <!--打包方式-->    <packaging></packaging>    <name>xx</name>    <properties>    </properties>    <!--配置需要使用到的jar包-->    <dependencies        <dependency>            <groupId>**</groupId>            <artifactId>**</artifactId>            <version>**</version>            <!-- 依赖-->            <type></type>            <!--范围-->            <scope></scope>        </dependency>    </dependencies>    <!--配置需要用到的插件-->    <build>        <plugins>            <plugin>            </plugin>        </plugins>    </build>    <!--配置激活条件-->    <profiles>        <!--第一条,默认激活 -->        <profile>            <id></id>            <properties>            </properties>        </profile>    </profiles></project>
1 0
原创粉丝点击