linux添加maven库,Linux下使用nexus搭建maven仓库私服

有个maven私服可以很方便地管理我们的jar包和发布构建到远程仓库,本文就介绍了如何在linux下一步步使用nexus搭建maven私服

原文链接:

下载安装

解压后会在同级目录中,出现两个文件夹:nexus-2.11.4-01和sonatype-work,前者包含了nexus的运行环境和应用程序,后者包含了你自己的配置和数据。

解压命令:unzip nexus-2.11.4-01-bundle.zip

启动nexus

# cd nexus-2.11.4-01/bin/

# ls

jsw  nexus  nexus.bat

# ./nexus

Usage: ./nexus { console | start | stop | restart | status | dump }

# ./nexus start

****************************************

WARNING - NOT RECOMMENDED TO RUN AS ROOT

****************************************

Starting Nexus OSS...

Started Nexus OSS.

查看控制台:

# ./nexus console

****************************************

WARNING - NOT RECOMMENDED TO RUN AS ROOT

****************************************

Running Nexus OSS...

wrapper  | --> Wrapper Started as Console

wrapper  | Launching a JVM...

wrapper  | JVM exited while loading the application.

jvm 1    | wrapper  | Unable to start JVM: No such file or directory (2)

wrapper  | Reloading Wrapper configuration...

wrapper  | Launching a JVM...

wrapper  | JVM exited while loading the application.

jvm 2    | wrapper  | Unable to start JVM: No such file or directory (2)

wrapper  | Reloading Wrapper configuration...

wrapper  | Launching a JVM...

wrapper  | JVM exited while loading the application.

jvm 3    | wrapper  | Unable to start JVM: No such file or directory (2)

wrapper  | Reloading Wrapper configuration...

wrapper  | Launching a JVM...

wrapper  | JVM exited while loading the application.

jvm 4    | wrapper  | Unable to start JVM: No such file or directory (2)

wrapper  | Reloading Wrapper configuration...

wrapper  | Launching a JVM...

wrapper  | JVM exited while loading the application.

jvm 5    | wrapper  | Unable to start JVM: No such file or directory (2)

wrapper  | There were 5 failed launches in a row, each lasting less than 300 seconds.  Giving up.

wrapper  |   There may be a configuration problem: please check the logs.

wrapper  | 

启动失败,原因:未安装JDK

安装JDK后,查看控制台:

# ./nexus console

****************************************

WARNING - NOT RECOMMENDED TO RUN AS ROOT

****************************************

Running Nexus OSS...

Nexus OSS is already running.

控制台显示启动成功。

查看nexus日志:

# cd ../logs/

# ls -l

total 48

-rw-r--r-- 1 root root 43311 2015-09-16 19:46 wrapper.log

# tail -f wrapper.log

配置nexus

529a327fbbff966f5e71b5eb3f95b898.png

右上角以admin登陆,默认用户名/密码:admin/admin123。

a1b00087288a61d45e7ca3af84c08b67.png

3rd party、Snapshots、Releases这三个,分别用来保存第三方jar、项目组内部的快照、项目组内部的发布版.

手动添加第三方jar

将第三方的jar上传到nexus上面:

83c47c42724dc2855209828063e7e646.png

5efd4503d2475f3798cc3aacc7057f75.png

点击Upload Artifact(s)按钮提交后即上传。

查看上传的jar包如下:

280987db128c7f8b6bddc8c4bf327e20.png

在项目中使用私服的jar包配置pom.xml如下:

  4.0.0  com.vclk.mkt.crawler  MarketingCrawler  jar  0.3  MarketingCrawler  http://maven.apache.org                    nexus          Team Nexus Repository          http://yourhostname:8081/nexus/content/groups/public                              nexus          Team Nexus Repository          http://yourhostname:8081/nexus/content/groups/public                            de.innosystec          java-unrar          0.5        

Maven在项目根目录下执行mvn eclipse:eclipse命令时,所依赖的jar包都会从私服中下载到本地并关联上项目,私服中没有就会从网络上下载到私服,本地再从私服下载。

3dc46b83a0190a2c37598281e8e97336.png

自动发布构件到远程仓库

在工程的pom.xml中添加:

        nexus-releases      http://yourhostname:8081/nexus/content/repositories/releases/          nexus-snapshots      http://yourhostname:8081/nexus/content/repositories/snapshots/  

进入maven的安装目录apache-maven-3.1.1\conf目录下,向settings.xml配置文件中的语句块中添加如下所示:

        nexus-releases      admin      admin123          nexus-snapshots      admin      admin123  

进入windows命令行,在工程所在目录下执行

mvn deploy

所部署的包就自动上传到了nexus安装目录下的 /maven/nexus/sonatype-work/nexus/storage/releases/com/vclk/mkt/crawler/MarketingCrawler/0.3 目录

nexus仓库中各目录介绍

项目中的各种jar包和项目快照等都放在 /nexus/sonatype-work/nexus/storage/ 目录下,在这个目录下包括以下各种目录和存放相应文件。

/nexus/sonatype-work/nexus/storage/central - 用于放置maven从中央仓库中下载下来的项目pom.xml中配置到的相关jar包;

/nexus/sonatype-work/nexus/storage/thirdparty - 用于放置自己手动上传的第三方jar包;

/nexus/sonatype-work/nexus/storage/releases - 用于放置项目deploy后的发布版。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值