Maven应用1-项目jar的管理及项目发布

目标:通过maven实现项目lib内容管理,并实现项目的maven包管理

一、安装maven环境

1、下载maven文件(这里用的是apache-maven-3.3.3-bin.tar.gz),下载页面:http://maven.apache.org/download.cgi

2、解压后将文件放到某个安装位置如:/Users/firefly/app/

3、使用终端执行vi ~/.bash_profile 编辑当前用户的环境变量加入以下内容:

#maven –start—
export PATH=$PATH:/Users/firefly/app/apache-maven-3.3.3/bin
export MAVEN_OPTS=”-Xms256m -Xmx512m”
JAVA_HOME=$(/usr/libexec/java_home)
export JAVA_HOME
#maven –stop–

4、在终端执行 mvn

–version 提示下面代码说明安装成功

Apache Maven 3.3.3(7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T19:57:37+08:00)

二、建立Eclipse与maven的关联

1,在Eclipse中找到Maven->Installations 添加本地安装的maven,并在User Settings中选择全局配置文件(一般在.m2/settings.xml或maven安装目录的conf/settings.xml)

2,在settings.xml中修改或添加下面内容:

<profile>
<id>nexus</id>
<repositories>
<repository>
<id>zj-nexus</id>
<name>local private nexus</name>
<url>http://172.16.1.12:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>

 

==================
<activeprofiles>
<activeprofile>nexus</activeprofile>
</activeprofiles>
==================
<mirrors>
<mirror>
<id>zj-nexus</id>
<mirrorof>central</mirrorof>
<name>central repository</name>
<url>http://172.16.1.12:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>
==================
<servers>
<server>
<id>user-release</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>user-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>

三、将项目与maven关联

1,项目右键->Configure->Convert to Maven Project 并设置group Id,Artifact Id,Version,Packaging
2,设置pom.xml添加与nexus服务器的关联(一个是发布版,一个是快照版)

<distributionManagement>
<repository>
<id>user-release</id>
<name>release</name>
<url>http://172.16.1.12:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>user-snapshots</id>
<name>inqORM snapshots</name>
<url>http://172.16.1.12:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

3,在项目pom.xml中的dependencies节点下添加以下内容来获取jar资源:
4,再右键项目执行Run As -> Maven Install获取jar

<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>

四、发布项目到maven

1,在Eclipse中Run Configuration中配置Maven Build 设置如下内容
name为 deploy
Base directory为 ${workspace_loc:/${project_name}}
Goals为 deploy -e
2,选择要发布的项目执行Run deploy实现将项目发布到快照(发布到哪个下面取决于pom中的version,
当version为xx–SNAPSHOT时发布为快照版本)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,837评论 18 139
  • 我jdk版本是1.7.0_95,在网上查了一下1.7属于java7maven3.3+版本都支持java7,所以我使...
    liangxifeng833阅读 1,285评论 0 2
  • Maven编译代码的相关命令 第一、main目录下的主代码编写完毕后,使用Maven进行编译,在项目根目录下运行命...
    加油小杜阅读 1,230评论 0 2
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,926评论 6 342
  • 今天听得课是怎样培养孩子的注意力。 本节课从四个方面讲述如何培养孩子的注意力。 一,身体发育 孩子身体平衡感不好,...
    萌奶糖阅读 354评论 0 0