Maven 私服配置

Maven 私服配置

上传

  1. 将项目发布到私服 ,修改 settings.xml 文件,配置连接私服的用户和密码 。此用户名和密码用于私服校验,因为私服需要知道上传的账号和密码是否和私服中的账号和密码一致。

  2. releases 连接发布版本项目仓库

    snapshots 连接测试版本项目仓库

<servers>
    <server>
        <id>releasesid>
        <username>adminusername>
        <password>admin123password>
    server>
    <server>
        <id>snapshotsid>
        <username>adminusername>
        <password>admin123password>
    server>
    <server>   
    	<id>thirdpartyid>   
    	<username>adminusername>
    	<password>admin123password>   
	server>
servers> 
  1. 第二步: 配置项目pom.xml
  2. 配置私服仓库的地址,本公司的自己的jar包会上传到私服的宿主仓库,根据工程的版本号决定上传到哪个宿主仓库,如果版本为release则上传到私服的release仓库,如果版本为snapshot则上传到私服的snapshot仓库
  3. 注意:pom.xml这里 和 settings.xml 配置 对应!
  4. 对工程执行deploy命令完成上传。
<groupId>nts.natashagroupId>
    <artifactId>nts_01artifactId>
    <version>1.0-SNAPSHOTversion>
<packaging>warpackaging>
<distributionManagement>
    <repository>
        <id>releasesid>
        <url>http://192.168.100.102:8081/nexus/content/repositories/releases/url>
    repository>
    <snapshotRepository>
        <id>snapshotsid>
        <url>http://192.168.100.102:8081/nexus/content/repositories/snapshots/url>
    snapshotRepository>
distributionManagement>

下载

  1. 在客户端的setting.xml中配置私服的仓库,由于setting.xml中没有repositories的配置标签需要使用profile定义仓库。

    此文件可以在pom父目录配置,打包时候可以自动找到私服!!!

<profiles>
    <profile>   
        
        <id>devid>   
        <repositories>   
            <repository>  
                
                <id>nexusid>   
                
                <url>http://192.168.100.102:8081/nexus/content/groups/public/url>   
                
                <releases>   
                    <enabled>trueenabled>   
                releases>   
                
                <snapshots>   
                    <enabled>trueenabled>   
                snapshots>   
            repository>   
        repositories>  
        <pluginRepositories>  
            
            <pluginRepository>  
                
                <id>publicid>  
                <name>Public Repositoriesname>  
                <url>http://192.168.100.102:8081/nexus/content/groups/public/url>  
            pluginRepository>  
        pluginRepositories>  
    profile>  
profiles>

上传第三方JAR包

  • 需要在maven软件的核心配置文件settings.xml中配置第三方仓库的server信息,以下配置不需要配置到服务器

  • 才能执行以下命令,执行CMD

mvn deploy:deploy-file

-DgroupId=com.alibaba

-DartifactId=fastjson

-Dversion=1.1.37

-Dpackaging=jar

-Dfile=fastjson-1.1.37.jar

-Durl=http://localhost:8081/nexus/content/repositories/thirdparty/

-DrepositoryId=thirdparty

<server>   
    <id>thirdpartyid>   
    <username>adminusername>
    <password>admin123password>   
server>
  • 还有一个方法,直接将整个目录下载之后,拷贝至 thirdparty/目录下可以直接上传私服

你可能感兴趣的:(linux,maven)