maven 服务搭建和使用

本文介绍了Maven作为项目管理工具的基本概念,并详细说明如何通过Nexus搭建私有仓库,包括Nexus的安装配置及Maven环境变量设置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.maven简介

Maven是基于项目对象模型( POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件 项目管理工具
Maven这个单词来自于意第绪语,意为知识的积累,最早在Jakata Turbine项目中它开始被用来试图简化构建过程。当时有很多项目,它们的Ant build文件仅有细微的差别,而JAR文件都由CVS来维护。于是Maven创始者开始了Maven这个项目,该项目的清晰定义包括,一种很方便的发布项目信息的方式,以及一种在多个项目中共享JAR的方式。

现在业界基本都会使用maven管理项目,可编译打包,单元测试等等;会用Nexus来做私服。

为自己的团队搭建属于自己的maven私服,这样既节省了网络带宽也会加速项目搭建。


2、Nexus下载

下载地址:http://www.sonatype.org/nexus/go 

 

3.安装配置 Nexus

 > 上传包 nexus-2.9.1-02-bundle.zip 到服务器上。

 > 解压 : unzip nexus-2.9.1-02-bundle.zip

 > 启动 :如下操作 

 

注:报错是指没有指定用户,需修改 nexus 脚本 > vi nexus 后找到 RUN_AS_USER 属性,做如下修改:

> 再启动


即可访问 http://localhost:8081/nexus/            

注:

localhost 指安装机器 IP 

默认登录用户 admin/admin123


配置

> 进入nexus系统,点击左侧 Repositories 


> 选中三项中的Configuration中的Download Remote indexs修改为true


> 选择Repair Index 让Nexus远程下载索引文件。


> 将3rd party 的Configuration中的Deploment Policy修改为Allow Redeploy:



如上 私服基本配置完成。

4 需要下载  apache-maven-3.0.4-bin.zip  解压,配置环境变量。 M2_HOME

需要path 增加 %M2_HOME%/bin

确认maven 是否可用: mvn -version

 

配置maven 的settings.xml文件:

settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="<a target=_blank href="http://maven.apache.org/SETTINGS/1.0.0">http://maven.apache.org/SETTINGS/1.0.0</a>" xmlns:xsi="<a target=_blank href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"
    xsi:schemaLocation="<a target=_blank href="http://maven.apache.org/SETTINGS/1.0.0">http://maven.apache.org/SETTINGS/1.0.0</a> <a target=_blank href="http://maven.apache.org/xsd/settings-1.0.0.xsd">http://maven.apache.org/xsd/settings-1.0.0.xsd</a>">
  <localRepository>f:/.m2/repository</localRepository>
    <profiles>
        <profile>
            <id>DefaultProfile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <repositories>
             <repository>
              <id>nexus</id>
                    <name>nexus</name>
                    <url><span style="color:#ff6666;">http://10.10.113.195:8081/nexus/content/groups/public</span></url>
                    <layout>default</layout>
                    <releases>
                       <enabled>true</enabled>
                    </releases>
                    <snapshots>
       <enabled>true</enabled>
                    </snapshots>
             </repository>
                <repository>
                    <id>maven2-repository.dev.java.net</id>
                    <name>Java.net Repository for Maven</name>
                    <url>http://download.java.net/maven/2/</url>
                    <layout>default</layout>
                </repository>
            </repositories> 
        </profile>
    </profiles>
    <servers>
        <server>
            <id>nexus-releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <id>nexus-3dparty</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
    
    <activeProfiles>
     <activeProfile>nexus</activeProfile>
    </activeProfiles>
</settings>

红色字体为maven仓库路径。

> JAVA IDE 中需要引用maven 配置

注:IDE需要maven插件,资源中已上传。

 

一个maven 工程,非常简单的springMVC 工程,资源中存放,请参考。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值