How to build Maven private service and use Maven private service

1. Why do we use private servers?

There are two main purposes: first, to avoid downloading the components we need in our own projects directly from the remote warehouse; second, to deploy our own public components to a private warehouse (our own private server), which is convenient for shared across projects.

 

2. Construction of private server environment

Here we build based on Linux environment.

Step 1: Download the nexus package (wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2-03-bundle.tar.gz

);

Step 2: Unzip (tar -xzvf nexus-2.11.2-03-bundle.tar.gz -C nexus);

The third step: start (bin/nexus start);

Step 4: Access (http://116.62.40.32:8081/nexus), the default port after startup is 8081; note that the access address here uses the IP address directly, if you want to access through the domain name, we can add Nginx configuration to realise.

server {

    listen       80;

    server_name The domain name set by yourself;

 

    #charset koi8-r;

    access_log access log directory main;

 

    location / {

        proxy_redirect          off;

        proxy_set_header        Host            $host;

        proxy_set_header        X-Real-IP       $remote_addr;

        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

        client_max_body_size    64m;

        client_body_buffer_size 10M;

        proxy_buffers           32 4k;

        proxy_connect_timeout   3;

        proxy_send_timeout      30;

        proxy_read_timeout      30;

        proxy_pass http://127.0.0.1:8081;//The access path of the proxy

    }

 

    #error_page  404              /404.html;

 

    # redirect server error pages to the static page /50x.html

    #

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

}

 

3. Private use

1. Default login account: username-admin, password-admin123

2. Create your own warehouse;



 

 

3. Let each of your projects use the private server to download components - modify Maven's settings.xml file (complete configuration)

<?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">

 

<localRepository>/Users/wuhoujian/Documents/m2/repository</localRepository>

<pluginGroups>

</pluginGroups>

 

<proxies>

</proxies>

 

<servers>

<server>

<id>jhzz-releases</id>

<username>xxx</username>

<password>xxx</password>

</server>

<server>

<id>jhzz-snapshots</id>

<username>xxx</username>

<password>xxx</password>

</server>

</servers>

 

<mirrors>

    <mirror>

        <id>jhzz-nexus</id>

        <mirrorOf>*</mirrorOf>

        <name>MyRepository</name>

        <!--private server warehouse address-->

        <url>Your own private server address/nexus/content/groups/public/</url>

    </mirror>

  </mirrors>

 

<profiles>

<profile>

        <id>jhzz-nexus</id>

        <repositories>

            <repository>

                <id>central</id>

                <name>MyRepository</name>

                <url>http://central</url>

                <releases>

                     <enabled>true</enabled>

                     <updatePolicy>always</updatePolicy>

                </releases>

                <snapshots>

                     <enabled>true</enabled>

                     <updatePolicy>always</updatePolicy>

                </snapshots>

            </repository>

        </repositories>

        <pluginRepositories>

            <pluginRepository>

                <id>central</id>

                <url>http://central</url>

                <releases>

                     <enabled>true</enabled>

                     <updatePolicy>always</updatePolicy>

                </releases>

                <snapshots>

                     <enabled>true</enabled>

                     <updatePolicy>always</updatePolicy>

                </snapshots>

            </pluginRepository>

        </pluginRepositories>

</profile>

</profiles>

 

<activeProfiles>

<activeProfile>jhzz-nexus</activeProfile>

</activeProfiles>

</settings>

 

4. How to deploy my own components to the private server?

Step 1: Add permission authentication configuration to settings.xml, otherwise the deployment of components cannot be completed;

Step 2: Modify the pom.xml file of the project;

<distributionManagement>

<repository>

<id>jhzz-releases</id>

<name>JHZZ Releases Repository</name>

<url>http://nexus.jihezhizao.com/nexus/content/repositories/jhzz-releases/</url>

</repository>

<snapshotRepository>

<id>jhzz-snapshots</id>

<name>JHZZ Snapshots Repository</name>

<url>http://nexus.jihezhizao.com/nexus/content/repositories/jhzz-snapshots/</url>

</snapshotRepository>

</distributionManagement>

Step 3: Deploy the component to the private server;

Simple deployment: mvn clean deploy

Complex deployment: mvn clean source:jar deploy -D maven.test.skip=true (deploy the component and the corresponding source code at the same time, so that we can view the source code by introducing our own deployed components into the project)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326305899&siteId=291194637