Maven:利用mvn deploy命令將jar包上傳到nexus服務器

(一). 搭建nexus服務器java

1. 下載最新版本的nexus,下載地址:http://www.sonatype.org/nexus/go
shell

2. 打開壓縮包,能夠看到以下文件服務器

3. 啓動console-nexus.bat,就會啓動nexus服務器,訪問http://localhost:8081/nexus/就能夠獲得nexus管理界面。app


(二). Maven:利用mvn deploy命令將jar包上傳到nexus服務器url

1. 修改$HOME/setting.xml,在<profiles></profiles>標籤內增長一下內容spa

<profile>
    <id>DEV</id>
    <repositories>
        <repository>
            <id>nexus</id>
            <name>local_repositories</name>
            <url>http://localhost:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
</profile>

2. 修改$HOME/setting.xml,在<servers></servers>標籤內增長一下內容code

<server>
   <id>releases</id> <!-- nexus倉庫的ID,好比這裏選的是releases倉庫 -->
   <username>deployment</username> <!-- 這裏使用的是nexus的賬號:deployment,能夠在nexus服務器管理 -->
   <password>deployment123</password> <!-- deployment賬號默認密碼: deployment123 -->
</server>

3. 修改項目下的pom.xml,在<project></project>標籤內增長以下內容server

<distributionManagement>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>

    <repository>
        <id>releases</id>
        <name>Nexus Release Repository</name>
        <url>http://localhost:8081/nexus/content/repositories/releases</url>
    </repository>
</distributionManagement>

4. 訪問http://localhost:8081/nexus/,將releases倉庫的Deployment Policy的只修改成Allow Redeploy,以下圖xml

4. 在項目下執行mvn deploy命令,執行成功後,訪問http://localhost:8081/nexus/content/repositories/releases/找到剛纔上傳成功的jar包get

mvn deploy:deploy-file -DgroupId=app.xxx -DartifactId=xxx -Dversion=1.0 -Dpackaging=jar -Dfile=D:\java\picture_server\target\xxx-1.0-SNAPSHOT.jar -Durl=http://localhost:8081/nexus/content/repositories/releases/ -DrepositoryId=releases

說明:

-Dversion:解壓縮xxx-1.0-SNAPSHOT.jar,查看文件META-INF/MANIFEST.MF,找到Manifest-Version對應的項,切不可取pom.xml文件裏面的版本值。

相關文章
相關標籤/搜索