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

说明你的包已经发布成功了。

猜你喜欢

转载自blog.csdn.net/yimcarson/article/details/84831731