访问http://nexus.sonatype.org/downloads/下载Nexus。
启动Nexus,就是启动一个web服务器,它的默认地址是localhost:8081。Nexus在一个名为Jetty的servlet容器中运行,它使用一个名为Tanuki Java Service Wrapper的本地服务包裹器启动。这个服务包裹器可以被配置成以Windows服务或Unix守护线程的形式运行Nexus。要启动Nexus,你需要为你的平台找到合适的启动脚本。要查看可用平台的列表,查看${NEXUS_HOME}/bin/jsw目录的内容。
可执行文件在%nexus安装目录%\nexus-webapp-1.0.0\binjsw\windows-x86-32下:
InstallNexus.bat/UninstallNexus.bat是安装/卸载nexus为windows service。
Nexus.bat是直接在命令行中启动Nexus,如果不想安装Nexus为windows service,可以用这个文件来手工控制Nexus的启动退出。
1.配置nexus
首先登录,默认地址http://localhost:8081/nexus/,默认用户名密码为admin/admin123.
nexus默认是关闭远程索引下载功能的。开启的方式:
点击Administration菜单下面的Repositories,将这三个仓库Apache Snapshots,Codehaus Snapshots,Maven Central的
Download Remote Indexes修改为true。然后在这三个仓库上分别右键,选择Re-index,这样Nexus就会去下载远程的索引文件。
2.管理仓库
以管理员用户登陆然后点击左边导航菜单Administration下面的Repositories。Nexus提供了三种不同的仓库。
(1)代理仓库
一个代理仓库是对远程仓库的一个代理。默认情况下,Nexus自带了如下配置的代理仓库:
Apache Snapshots
这个仓库包含了来自于Apache软件基金会的快照版本。http://people.apache.org/repo/m2-snapshot-repository
Codehaus Snapshots
这个仓库包含了来自于Codehaus的快照版本。 http://snapshots.repository.codehaus.org/
Central Maven Repository
这是中央Maven仓库(发布版本)。 http://repo1.maven.org/maven2/
(2)宿主仓库
一个宿主仓库是由Nexus托管的仓库。Maven自带了如下配置的宿主仓库。
3rd Party
这个宿主仓库应该用来存储在公共Maven仓库中找不到的第三方依赖。这种依赖的样例有:你组织使用的,商业的,私有的类库如Oracle JDBC驱动。
Releases
这个宿主仓库是你组织公布内部发布版本的地方。
Snapshots
这个宿主仓库是你组织发布内部快照版本的地方。
(3)虚拟仓库
一个虚拟仓库作为Maven 1的适配器存在。Nexus自带了一个central-m1虚拟仓库
3. 管理组
组是Nexus一个强大的特性,它允许你在一个单独的URL中组合多个仓库。Nexus自带了两个组:public和public-snapshots。public组中组合了三个宿主仓库:3rd Party, Releases, 和Snapshots,还有中央Maven仓库。而public-snapshots组中组合了Apache Snapshots和Codehaus Snapshots仓库。
4. 配置maven
要让maven使用Nexus作为仓库,要修改~/.m2/settings.xml.
- <profiles>
-
<profile>
-
<id>nexus</id>
-
<repositories>
-
<repository>
-
<id>nexus</id>
-
<name>local private nexus</name>
-
<url>http://localhost:8081/nexus/content/groups/public</url>
-
</repository>
-
</repositories>
-
</profile>
-
<profile>
-
<id>nexus-snapshots</id>
-
<repositories>
-
<repository>
-
<id>nexus-snapshots</id>
-
<name>local private nexus snapshots</name>
-
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
-
</repository>
-
</repositories>
-
</profile>
-
</profiles>
-
-
<activeProfiles>
-
<activeProfile>nexus</activeProfile>
-
<activeProfile>nexus-snapshots</activeProfile>
-
</activeProfiles>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://localhost:8081/nexus/content/groups/public</url>
</repository>
</repositories>
</profile>
<profile>
<id>nexus-snapshots</id>
<repositories>
<repository>
<id>nexus-snapshots</id>
<name>local private nexus snapshots</name>
<url>http://localhost:8081/nexus/content/groups/public-snapshots</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>nexus-snapshots</activeProfile>
</activeProfiles>
5.部署构件至Nexus
要部署构件至Nexus,在distributionManagement中提供仓库URL,然后运行mvn deploy。Maven会通过一个简单的HTTP PUT将项目POM和构件推入至你的Nexus安装。需要配置你项目POM中distributionManagement部分的repository。
- <distributionManagement>
-
<repository>
-
<id>releases</id>
-
<name>Internal Releases</name>
-
<url>http://localhost:8081/nexus/content/repositories/releases</url>
-
</repository>
-
<snapshotRepository>
-
<id>Snapshots</id>
-
<name>Internal Snapshots</name>
-
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
-
</snapshotRepository>
-
</distributionManagement>
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>Snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
这样还没完,这时如果部署会报错,还要在~/.m2/settings.xml中添加如下的服务器登录信息:
- <server>
-
<id>releases</id>
-
<username>admin</username>
-
<password>admin123</password>
-
</server>
-
<server>
-
<id>Snapshots</id>
-
<username>admin</username>
-
<password>admin123</password>
-
</server>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>Snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
部署第三方构件:
构件可能是私有数据库的JDBC驱动如Oracle,或者你依赖于另一个JAR,它既不开源也无法免费获得。在这样的情况下,你就需要手动拿来这些构件然后发布到你自己的仓库中。Nexus提供宿主的"third-party"仓库,就是为了这个目的。
使用以下命令发布该文件至Nexus:
- mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc14
-
-Dversion=10.2.0.3.0 -Dpackaging=jar -Dfile=ojdbc.jar
-
-Durl=http:
- -DrepositoryId=thirdparty
mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc14
-Dversion=10.2.0.3.0 -Dpackaging=jar -Dfile=ojdbc.jar
-Durl=http://localhost:8081/nexus/content/repositories/thirdparty
-DrepositoryId=thirdparty
6.Nexus监听端口
默认情况下,Nexus监听端口8081。你可以更改这个端口,通过更改${NEXUS_HOME}/conf/plexus.properties的值,为此,停止Nexus,更改文件中applicationPort的值,然后重启Nexus。
7.Maven Profiles
Maven中的profile是一组可选的配置,可以用来设置或者覆盖配置默认值。有了profile,你就可以为不同的环境定制构建。profile可以在pom.xml中配置,并给定一个id。然后你就可以在运行Maven的时候使用的命令行标记告诉Maven运行特定profile中的目标。以下pom.xml使用production profile覆盖了默认的Compiler插件设置。
- <profiles>
-
<profile>
-
<id>production</id>
-
<build>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-compiler-plugin</artifactId>
-
<configuration>
-
<debug>false</debug>
-
<optimize>true</optimize>
-
</configuration>
-
</plugin>
-
</plugins>
-
</build>
-
</profile>
-
</profiles>
<profiles>
<profile>
<id>production</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>false</debug>
<optimize>true</optimize>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
要使用production profile来运行mvn install,你需要在命令行传入-Pproduction参数。要验证production profile覆盖了默认的Compiler插件配置,可以像这样以开启调试输出(-X) 的方式运行Maven。
如果你开始大量使用Maven profile,你会希望将profile从POM中分离,使用一个单独的文件如profiles.xml。你可以混合使用定义在pom.xml中和外部profiles.xml文件中的profile。只需要将profiles元素放到${basedir}目录下的profiles.xml文件中,然后照常运行Maven就可以。profiles.xml文件的大概内容如下:
- <profiles>
-
<profile>
-
<id>development</id>
-
<build>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-compiler-plugin</artifactId>
-
<configuration>
-
<debug>true</debug>
-
<optimize>false</optimize>
-
</configuration>
-
</plugin>
-
</plugins>
-
</build>
-
</profile>
-
<profile>
-
<id>production</id>
-
<build>
-
<plugins>
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-compiler-plugin</artifactId>
-
<configuration>
-
<debug>false</debug>
-
<optimize>true</optimize>
-
</configuration>
-
</plugin>
-
</plugins>
-
</build>
-
</profile>
-
</profiles>
<profiles>
<profile>
<id>development</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>true</debug>
<optimize>false</optimize>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>production</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>false</debug>
<optimize>true</optimize>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
settings profile可以应用到所有你使用Maven构建的项目。你可以在两个地方定义settings profile:定义在~/.m2/settings.xml中的用户特定settings profile,或者定义在${M2_HOME}/conf/settings.xml中的全局settings profile。
分享到:
相关推荐
Nexus 是Maven仓库管理器,如果你使用Maven,你可以从Maven中央仓库 下载所需要的构件(artifact),但这通常不是一个好的做法,你应该在本地架设一个Maven仓库服务器,在代理远程仓库的同时维护本地仓库,以节省...
Maven私服搭建必备,完整的Maven私服和本地仓库搭建步骤
【Android Gradle 插件】将自定义 Gradle 插件上传到自建 Maven 仓库 ⑤ ( 使用 Sonatype Nexus 搭建 Maven 仓库 ) https://hanshuliang.blog.csdn.net/article/details/127385094 博客资源
nexus-maven仓库管理软件-使用手册(pdf格式)
Linux下Maven以及Nexus的安装,以及服务器端与客户端的配置
由于官网下载速度较慢,故在此进行分享下载。 Windows中Maven仓库管理工具:Nexus,版本文件:nexus-3.47.1-01-win64.zip
nexus Maven
首先介绍一下Maven的仓库,然后在说一下如何通过Nexus来建立我们自己的仓库,以及如何使用。
Maven 本地仓库,远程仓库,中央仓库,Nexus私服,镜像 详解,只要学通了这边文章,maven配置你随便折腾
Maven 仓库是项目中依赖的第三方库,这个库所在的位置叫做仓库。 在 Maven 中,任何一个依赖、插件或者项目构建的输出,都可以称之为构件。 Maven 仓库能帮助我们管理构件(主要是...较为新版的maven仓库,值得拥有.
当前最流行的Maven仓库管理软件,节省带宽和时间,在局域网内架设一个私有的仓库服务器,用其代理所有外部的远程仓库。当本地Maven项目需要下载构件时,先去私服请求,如果私服没有,则再去远程仓库请求,从远程仓库...
阿里云云效 是企业级一站式 DevOps 平台,覆盖产品从需求到运营的研发全生命周期,其中云效也提供了免费、可靠的Maven私有仓库 Packages 和代码管理仓库 Codeup,欢迎您体验使用。 云效制品仓库 Packages 致力于帮助...
Nexus 是Maven仓库管理器,可用于搭建maven私服。在本地架设一个Maven仓库服务器,在代理远程仓库的同时维护本地仓库,以节省带宽和时间,Nexus就可以满足这样的需要。
一个专门的 Maven 仓库管理软件,用于搭建 Maven 私服。本版本是2021年3月Unix最新版 3.30.0
主要为大家详细介绍了微信开发准备第一步,Maven仓库管理新建WEB项目,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
Nexus 是Maven仓库管理器,如果你使用Maven,你可以从Maven中央仓库 下载所需要的构件(artifact),但这通常不是一个好的做法,你应该在本地架设一个Maven仓库服务器,在代理远程仓库的同时维护本地仓库,以节省...
Nexus是Sonatype推出的强大Maven仓库管理器产品。有以下优点: 代理远程仓库。配置Nexus代理中央仓库,其它任何公开的Maven仓库,将你组织内部的Maven配置指向Nexus,这样所有构件都将从Nexus下载,如果Nexus没有你...
Maven仓库java项目仓库管理使用,解压放在某目录直接在编程工具纸箱改文件的配置
文档总结了搭建maven私服管理器nexus时遇到的一些问题,建议各位使用nexus2.*版本; 文档描述了pom以及setting的一些配置
maven管理项目从安装到使用过程,同时带有总结,做项目少不了管理,如果只是做一个hello world项目,那当然你可以不用考虑使用maven等来管理项目,但是你应该不会只做着娱乐,所以有必要学习maven等管理项目的方法 ,...