码迷,mamicode.com
首页 > 系统相关 > 详细

Linux安装Maven

时间:2016-05-10 18:59:54      阅读:419      评论:0      收藏:0      [点我收藏+]

标签:maven

Apache Maven,是一个软件(特别是Java软件)项目管理及自动构建工具,由Apache软件基金会所提供。基于项目对象模型(POM)概念,Maven利用一个中央信息片断能管理一个项目的构建、报告和文档等步骤。曾是Jakarta项目的子项目,现为独立Apache项目。

现在有很多Apache项目都已经开始采用Maven进行管理。


1、Maven下载地址:

http://apache.fayea.com/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

2、源码安装:

# tar zxvf apache-maven-3.3.9-bin.tar.gz

# cp -r apache-maven-3.3.9 /usr/maven

3、修改环境变量:

vim /etc/profile.d/maven.sh

添加下面内容:

M2_HOME=/usr/maven
PATH=$PATH:$M2_HOME/bin
export M2_HOME PATH

保存退出vi编辑器

# source /etc/profile 



4、若成功,输入#mvn -v后显示:

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)

Maven home: /usr/maven

Java version: 1.7.0_79, vendor: Oracle Corporation

Java home: /usr/java/jdk1.7.0_79/jre

Default locale: en_US, platform encoding: UTF-8

OS name: "linux", version: "2.6.32-431.23.3.el6.x86_64", arch: "amd64", family: "unix"

看到Maven相关版本信息,则说明Maven已经安装成功


5.配置maven

编辑maven的配置文件

# cd /usr/maven/conf/# vi settings.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">
    <localRepository>/home/gistech/~m2</localRepository>
    <servers>
        <server>
            <username>admin</username>
            <password>password</password>
        </server>
    </servers>
    <mirrors>
        <mirror>
            <!-- This sends everything else to /public -->
            <id>nexus</id>
            <mirrorOf>central</mirrorOf>
            <url>http://192.168.120.247:8081/nexus/content/repositories/public</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>nexus</id>
            <!-- Enable snapshots for the built in central repo to direct -->
            <!-- all requests to nexus via the mirror -->
            <repositories>
                <repository>
                    <id>central</id>
                    <url>http://192.168.120.247:8081/nexus/content/repositories/public</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>http://192.168.120.247:8081/nexus/content/repositories/public</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <!-- make the profile active all the time -->
        <activeProfile>nexus</activeProfile>
    </activeProfiles>

    <pluginGroups>
        <!-- define the sonatype plugin group, so the nexus plugins will work without typing the groupId-->
        <pluginGroup>org.sonatype.plugins</pluginGroup>
    </pluginGroups>
</settings>

其中localRepository节点表示私服中下载的jar包存放路径,根据实际存放的路径修改。

所有url节点中包含的地址:http://192.168.120.247:8081/nexus/content/repositories/public,表示nexus私服的地址,请根据实际的地址修改。

username、password节点表示登录nexus私服的用户名及密码。


Maven常用命令

Maven的命令非常多,学习命令首先要了解Maven的生命周期。

Maven首先会验证并处理引用资源,之后进行项目编译,如果没有声明跳过测试,也会编译测试代码并进行测试、以成测试报告。最后,Maven会将编译好的内容进行打包,用于发布。

Maven命令与Maven的生命周期有着对应的关系,一个命令也经常会包含多个生命周期,比如mvn package会完成以上所有步骤。

这里列举几个常用的命令

mvn compile 编译项目

mvn test 编译运行单元测试

mvn package 打包(jar or war)

mvn install 将项目安装到本地仓库

mvn clean 清空项目

mvn eclipse:eclipse 生成eclipse工程






本文出自 “运维·人生” 博客,谢绝转载!

Linux安装Maven

标签:maven

原文地址:http://qiangsh.blog.51cto.com/3510397/1771831

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