Nexus3.x.x上传第三方jar

来源:互联网 发布:云计算厂商 编辑:程序博客网 时间:2024/05/22 08:19

Nexus3.x.x上传第三方jar:

1.create repository



选择maven2(hosted),这里的Repository的type属性有:proxy,hosted,group三种

proxy:即你可以设置代理,设置了代理之后,在你的nexus中找不到的依赖就会去配置的代理的地址中找

hosted:你可以上传你自己的项目到这里面

group:它可以包含前面两个,是一个聚合体。一般用来给客户一个访问nexus的统一地址。

简单的说,就是你可以上传私有的项目到hosted,以及配置proxy以获取第三方的依赖(比如可以配置中央仓库的地址)。前面两个都弄好了之后,在通过group聚合给客户提供统一的访问地址。

新建的reposity如下

2.赋权

修改maven安装目录下的/conf/settings.xml文件,添加serve如下


<servers>
<server>
<id>3rdParty</id>
<username>admin</username>
<password>admin123</password>
</server>

</servers>

3.上传jar

第一种方式:直接上传jar

如果已经有了jar包,可以通过下面的命令直接上传,cmd中输入下列命令

mvn deploy:deploy-file -DgroupId=xxx.xxx -DartifactId=xxx -Dversion=0.0.2 -Dpackaging=jar -Dfile=D:\xxx.jar -Durl=http://xxx.xxx.xxx.xxx:8081/repository/3rdParty/ -DrepositoryId=3rdParty

其中-DgroupId 为上传的jar的groupId

-DartifactId 为上传的jar的artifactId

-Dversion 为上传的jar的需要被依赖的时候的版本号

然后是-Dpackaging为jar,-Dfile为jar包路径 

-Durl 为要上传的路径,可以通过以下方式获取到

     

-DrepositoryId 为repository的唯一标示,跟第二步中赋权配置的server相同


mvn deploy:deploy-file -DgroupId=com.danga -DartifactId=memcached -Dversion=2.6.6 -Dpackaging=jar -Dfile=java_memcached-release_2.6.6.jar -Durl=http://localhost:8081/repository/maven-thirtypart/ -DrepositoryId=maven-thirtypart

在实际执行命令的时候可能会报错,根据错误信息提示:

[ERROR] Failed to execute goalorg.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file(default-cli) on project standalone-pom:Failed to deploy artifacts: Could not transfer artifact com.danga:memcached:jar:2.6.6 from/to 3rdParty (http://localhost:8081/repository/maven-thirtypart/): Failed to transfer file: http://localhost:8081/repository/maven-thirtypart/com/danga/memcached/2.6.6/memcached-2.6.6.jar. Return code is: 401, ReasonPhrase: Unauthorized. ->[Help 1]

鉴权失败,需要在settting.xml文件中增加鉴权验证的配置

<server> 

         <id>maven-thirtypart</id>  

         <username>admin</username>  

         <password>admin</password>

</server>


第二种方式:直接将项目发布到仓库中

在项目的pom.xml中加入下面的配置:


<distributionManagement>  

        <repository>  
            <id>3rdParty</id>  
            <name>3rdParty Repository</name>  
            <url>http://xxx.xxx.xxx.xxx:8081/repository/3rdParty/</url>  
        </repository>  
    </distributionManagement> 

id为要上传的repository的唯一标示,url为要上传的repository的路径

然后在pom.xml文件所在文件夹打开cmd窗口输入mvn deploy即可

原创粉丝点击