SonaType Nexus上传自定义Jar包

本文介绍了如何通过pom文件和自定义方式将自定义的Jar包上传到SonaType Nexus。首先,可以在Maven工程中添加依赖并编译到本地,然后通过Nexus的Artifact Upload从POM文件导入。另一种方法是直接在Nexus上设置GAV参数,上传jar包及其源码。参考链接提供了详细的步骤说明。

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

<dependency>
			<groupId>org.apache.pthrift</groupId>
			<artifactId>thrift-plugin</artifactId>
			<version>0.1.10</version>
		</dependency>

SonaType Nexus上传自定义Jar包两种方式

1.pom文件方式

        1.1:在正常使用的maven工程中添加依赖,指定groupId,artifactId,version

              

        1.2:编译加载至本地

                       mvn install:install-file -DgroupId=org.apache.pthrift DartifactId=thrift-plugin                  -Dversion=0.1 -Dpackaging=jar -Dfile=/home/ubuntu/saxon-dom-9.0.jar

        1.3:打开Nexus三方库的Artifact Upload--->GAV Definition选择From POM

        1.4找到本地库的相应文件下的pom.xml文件上传



2.自定义方式jar包

        2.1:打开Nexus三方库的Artifact Upload--->GAV Definition选择GAV Paramet

        2.2:设置Group组名,Artifact和version版本号,添加自定义jar包,source包等



参考:http://blog.youkuaiyun.com/shuhuai007/article/details/7564931

            http://michael-tuan.iteye.com/blog/375686 

<think>我们正在讨论如何在Nexus上传JAR自定义属性。NexusRepositoryManager允许用户在上传组件时添加自定义属性,这些属性可以用于搜索、分类和管理组件。步骤:1.使用Nexus提供的RESTAPI上传JAR,并在请求中自定义属性。2.在Maven构建中,使用nexus-staging-maven-plugin(对于Maven项目)来上传并设置属性。方法一:使用RESTAPI上传并设置属性我们可以使用curl命令来上传JAR并设置自定义属性。例如:```bashcurl-v-uusername:password--upload-fileyourfile.jar\"http://nexus-server/service/rest/v1/components?repository=your-repo-name"\-H"Content-Type:application/json"\-H"accept:application/json"\--data'{"version":"1.0.0","assets":[{"path":"/path/to/yourfile.jar","file":"yourfile.jar"}],"attributes":{"custom":{"key1":"value1","key2":"value2"}}}'```注意:这里我们通过`--data`参数传递了一个JSON对象,其中含了版本、资产(assets)和属性(attributes)。在attributes下的custom对象中,我们可以添加任意键值对。方法二:使用Maven插件如果你使用Maven构建项目,并希望在上传Nexus时设置属性,可以配置nexus-staging-maven-plugin(适用于Nexus3):在pom.xml中:```xml<build><plugins><plugin><groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId><version>1.6.8</version><extensions>true</extensions><configuration><serverId>nexus</serverId><nexusUrl>http://nexus-server/</nexusUrl><autoReleaseAfterClose>true</autoReleaseAfterClose><properties><custom.key1>value1</custom.key1><custom.key2>value2</custom.key2></properties></configuration></plugin></plugins></build>```然后使用`mvndeploy`命令部署,插件会自动将属性添加到上传的组件中。注意:自定义属性的命名空间通常使用`custom.`作为前缀,但也可以根据Nexus配置使用其他前缀。验证:上传后,可以在Nexus的Web界面中查看组件的属性,或者通过RESTAPI搜索组件时使用这些属性进行过滤。引用:Nexus官方文档中关于组件上传和属性的部分[^1]。§§相关问题§§1.如何在Nexus中通过自定义属性搜索组件?2.除了RESTAPI和Maven插件,还有其他方法上传JAR并设置自定义属性吗?3.自定义属性在Nexus中有哪些应用场景?</think>### 在 Nexus 上传 JAR 自定义属性的方法 在 Nexus Repository Manager 中上传 JAR 时,可通过以下方式添加自定义属性: --- #### 方法 1:使用 REST API 上传(推荐) 通过 Nexus 的 REST API 在 JSON 请求体中直接添加自定义属性: ```bash curl -X POST -u "用户名:密码" \ -H "Content-Type: application/json" \ -H "accept: application/json" \ "http://nexus-host/service/rest/v1/components?repository=your-repo-name" \ -d '{ "version": "1.0.0", "assets": [{ "path": "/path/to/your.jar", "file": { "name": "your.jar" } }], "attributes": { # 自定义属性区域 "custom": { "team": "devops", "env": "production", "license": "MIT" } } }' ``` 关键参数: - `repository`:目标仓库名称 - `attributes.custom`:自定义键值对 - 支持批量添加多个属性[^1] --- #### 方法 2:使用 Maven 插件配置 在 `pom.xml` 中配置 `nexus-staging-maven-plugin`: ```xml <plugin> <groupId>org.sonatype.plugins</groupId> <artifactId>nexus-staging-maven-plugin</artifactId> <version>1.6.13</version> <configuration> <serverId>nexus</serverId> <nexusUrl>http://nexus-host</nexusUrl> <properties> <!-- 自定义属性 --> <custom.team>backend</custom.team> <custom.project>payment-service</custom.project> </properties> </configuration> </plugin> ``` 执行部署命令: ```bash mvn deploy -DaltDeploymentRepository=nexus::default::http://nexus-host/repository/your-repo/ ``` --- #### 方法 3:UI 界面手动添加 1. 在 Nexus 控制台上传 JAR 文件 2. 进入仓库浏览界面,选择对应组件 3. 点击 **Attributes** 标签页 ➜ **Add Custom Attribute** 4. 输入键值对并保存 --- ### 属性使用场景 1. **组件分类**:按环境(dev/prod)、团队、项目标记 2. **高级搜索**:在 Nexus 搜索栏使用 NXQL 查询: ```sql SELECT * FROM Component WHERE attributes.custom.team = "devops" ``` 3. **权限控制**:基于属性设置仓库防火墙规则 4. **自动化流程**:CI/CD 流水线根据属性触发操作 > ⚠️ 注意:属性键名需遵循 `custom.*` 命名规范,且需在 **Repository Manager ➜ Capabilities** 中启用 *Custom Metadata* 功能[^2]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值