1. 程式人生 > >maven私有服nexux安裝與配置&maven專案釋出jar包到nexux

maven私有服nexux安裝與配置&maven專案釋出jar包到nexux

nexux安裝與配置

安裝nexux

下載Nexus Repository Manager OSS 3.x,官網地址https://www.sonatype.com/download-oss-sonatype,複製下載連結,使用wget下載

wget https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.14.0-04-unix.tar.gz
tar -zxvf nexus-3.14.0-04-unix.tar.gz
mv nexus-3.14.0-04 /usr/local/nexus/
ln -s /usr/local/nexus/bin/nexus /usr/local/bin

測試一下

nexus

{start|stop|run|run-redirect|status|restart|force-reload}

看到這個提示,說明已經裝好了。

建立nexu使用者

nexus不推薦使用root使用者啟動,所以建立一個nexus使用者

useradd -d "/home/nexus" -m nexus

/usr/local/nexus是nexus程式路徑;/usr/local/sonatype-work是日誌需要的一個路徑。給這兩個路徑加許可權。

chown
-R nexus:nexus /usr/local/nexus
chown -R nexus:nexus /usr/local/sonatype-work

配置nexus的啟動使用者

vi /usr/local/nexus/bin/nexus.rc

run_as_user=“nexus”

啟動

nexus start

在maven專案中使用nexus

pom.xml配置

在maven專案中配置repositoriesdistributionManagement

    <repositories>
        <repository
>
<id>nexus_public</id> <name>maven-public</name> <url>http://<!--nexus host-->/repository/maven-public/</url> </repository> </repositories> <distributionManagement> <repository> <id>nexux_releases</id> <name>maven-releases</name> <url>http://<!--nexus host-->/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexux_snapshots</id> <name>maven-snapshots</name> <url>http://<!--nexus host-->/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>

distributionManagement.repository.iddistributionManagement.snapshotRepository.id需要在setting.xml中配置使用者資訊,否則執行mvn deploy會出現許可權錯誤,這些使用者可以在nexus的Web端管理頁面新增。

setting.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>nexux_snapshots</id>
      <username>deployment</username>
      <password><!--deployment使用者的密碼--></password>
    </server>
    <server>
      <id>nexux_releases</id>
      <username>deployment</username>
      <password><!--deployment使用者的密碼--></password>
    </server>
  </servers>
  <mirrors>
<!--
 <mirror>
 <id>alimaven</id>
 <name>aliyun maven</name>
 <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
 <mirrorOf>central</mirrorOf>
 </mirror>
-->
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://<!--nexus host-->/repository/maven-public/</url>
    </mirror>
  </mirrors>
  <profiles>
   <profile>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>nexus_public</id>
          <name>Nexus Public Repository</name>
          <url>http://<!--nexus host-->/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>
</settings>

測試

maven專案內(pom.xml所在的路徑)打包專案

mvn clean install -Dmaven.test.skip=true

-Dmaven.test.skip=true可以在打包時忽略測試用例,且不執行測試用例。

將打好的包釋出到nexus

mvn deploy

看到這樣的提示

Uploading to nexux_releases: http://***/repository/maven-releases/***/1.2.7.BETA/***-1.2.7.BETA.jar

說明你的包已經發布成功了。