Apache Maven,是一个软件项目管理及自动构建工具,由 Apache软件基金会所提供。

安装Maven

Java安装

[root@localhost ~]# yum -y install java-1.8.0-openjdk-devel

Maven安装

# 下载tar包
[root@localhost ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
# 解压tar包
[root@localhost ~]# tar zxf apache-maven-3.5.4-bin.tar.gz 
[root@localhost ~]# mv apache-maven-3.5.4 /usr/local/maven

配置环境变量

[root@localhost ~]# vim /etc/profile
# 末尾添加
MAVEN_HOME=/usr/local/maven
export MAVEN_HOME
export PATH=${PATH}:${MAVEN_HOME}/bin
[root@localhost ~]# source /etc/profile
[root@localhost ~]# mvn -version

Maven的简单使用

mavne加速

[root@localhost ~]# vim /usr/local/maven/conf/settings.xml
# Maven配置文件中的<mirrors></mirrors>中存放镜像的位置
# 找到<mirrors>,在其中添加如下代码,注意<mirrors>和<mirror>不一样
    <mirror>
        <id>aliyun maven</id>
        <name>aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>   # 代表本机去中央仓库的请求拦截,让阿里云来处理
    </mirror>

创建一个hello world的Maven项目

[root@localhost ~]# mvn archetype:generate -DgroupId=helloworld -DartifactId=helloworld

进入项目目录执行编译

[root@localhost ~]# cd helloworld
[root@localhost helloworld]# mvn compile

运行可以看到输出Hello World!

[root@localhost helloworld]# mvn exec:java -Dexec.mainClass='helloworld.App'

测试

[root@localhost helloworld]# mvn test

打包

[root@localhost helloworld]# mvn package

查看生成的java项目包

[root@localhost helloworld]# ls target/
classes                      maven-archiver  surefire-reports
helloworld-1.0-SNAPSHOT.jar  maven-status    test-classes

评论




正在载入...
PoweredHexo
HostedAliyun
DNSAliyun
ThemeVolantis
UV
PV
BY-NC-SA 4.0