maven深入了解

1、什么是maven
        项目管理和构建工具
        它包含了:
        一个项目对象模型 (Project Object Model),
        一组标准集合,
        一个项目生命周期(Project Lifecycle),
        一个依赖管理系统(Dependency Management System),
          和用来运行定义在生命周期阶段(phase)中插件(plugin)目标(goal)的逻辑。
        当你使用Maven的时候,你用一个明确定义的项目对象模型来描述你的项目,
        然后 Maven 可以应用横切的逻辑,这些逻辑来自一组共享的(或者自定义的)插件。

2、maven配制
        下载maven :  http://maven.apache.org/
         配制环境变量: M2_HOME

3、手动创建maven项目
    1、创建一个工程目录
    2、创建一个pom.xml    == >
              <modelVersion>4.0.0</modelVersion>  模型版本(固定)

                工程发布的定位坐标
              <groupId>com.yc.maven</groupId>   包的前缀名
              <artifactId>maven-hello</artifactId> 模块名
              <version>0.0.1-SNAPSHOT</version> 版本号  snapshot开发版  release稳定版

              <packaging>jar</packaging>  最后打包成什么(默认为jar)

              有依赖其它包:
                 依赖包坐标放在 <dependencies> </dependencies>中

                 查找坐标: http:search.maven.org

    3、创建源文件:
         源文件存放位置: src/main/java
         配置资源文件存放位置: src/main/resources
         测试源文件存放位置:src/test/java
         测试配置资源文件存放位置: src/test/resources

    4、maven命令
        mvn clean  : 清除
        mvn clean compile : 清除并编译源文件
        mvn clean test : 清除并编译源文件和测试源文件
        mvn clean package : 清除并编译源文件和测试源文件后, 再打包
        mvn clean install : 清除并编译源文件和测试源文件后, 再打包, 再安装到本地仓库
        mvn clean deploy : 清除并编译源文件和测试源文件后, 再打包, 再安装到本地仓库, 再安装私服

4、archetype:generate 创建maven项目


5、IDE创建maven项目


6、使用私服nexus
    a、只为一个项目配制(pom.xml):
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus</name>
            <url>http://私服nexus的ip地址:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>Nexus</name>
            <url>http://私服nexus的ip地址:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    b、本机所有项目都可以使用(settings.xml):

    <profiles>
        <profile>
        <id>nexus</id>
            <repositories>
                <repository>
                    <id>nexus</id>
                    <name>Nexus</name>
                    <url>http://私服nexus的ip地址:8081/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <name>Nexus</name>
                    <url>http://私服nexus的ip地址:8081/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>


    c、配置镜像让maven只使用nexus私服(settings.xml):

    <mirrors>
        <mirror>
            <id>nexus</id>
            <mirrorOf>*</mirrorOf>
            <url>http://私服nexus的ip地址:8081/nexus/content/groups/public/</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
        <id>nexus</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>http://central</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>http://central</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>


    d、部署构件至私服nexus(pom.xml)

    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Releases Repositories</name>
            <url>http://218.196.14.220:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshots Repositories</name>
            <url>http://218.196.14.220:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

    为部署构件到私服nexus配置认证信息(settings.xml)
    <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>
    </servers>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wen's

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值