Maven repository introduce and build PW

 

1 What is Maven?

The concept of 1.1 Maven

  Maven project primarily serves the Java platform to build on, rely on information management and project development, it is an unusually powerful build tool that can help us to automate the build process, from cleaning, compiling, testing to generate reports, to the packaging and deployment.

 

1.2 Maven advantage

1.2.1 convenient

  Using Maven biggest advantage is that easy. Construction of the project, developers do not need to enter commands over and over, again and again click of a mouse, we need to do is type a simple command Maven, Maven will help us deal with those tedious tasks.

1.2.2 standardized way to build

  Before using Maven, multiple projects may have a variety of ways to build; after using Maven, the way to build a number of projects to be unified, so largely avoids unnecessary learning costs, but also help standardize project team.

1.2.3 provides a central repository

  Not just Maven build tool, it is a dependency management tools, and project information management tools. It provides a common central warehouse, as long as we provide the necessary components of the project "coordinate", Maven can help us to automatically download, eliminating the need to manually find the time cost.

 

2 What is Maven repository

2.1 Maven repository concept

  In Maven world, a dependency any output, plug or the project build, can be referred to as members, each member has its own unique identification coordinates (mainly containing groupId, artifactId, version). The coordinates of the identifier, using any Maven project a member of any embodiment is identical. On this basis, Maven Maven project can be unified store all shared components in one place, this unified position is Maven repository.

       The actual Maven project will no longer be stored in each of its dependent files, they only need to declare these depend on the coordinates, (when the project is compiled), Maven will automatically find the coordinates of the warehouse components when needed and use them.

 

Category 2.2 Maven repository

2.2.1 Local Warehouse

  A local repository file that is stored in the unit disk folder, Maven download the components are stored in this folder. After you install the Maven software, by default in the user directory has a path ".m2 / repository /" repository directory, the directory path similar to the following form: "C: \ Users \ xxx \ .m2 \ repository \", in addition developers can edit Maven installation directory "conf" folder in the "settings.xml" file, which is set in the path of the local warehouse. This article focuses on specific settings is not, and will not be described, the reader may ask yourself Baidu.

 

2.2.2 remote repository

       As the name suggests, is a remote repository that is stored on a remote server file in the folder, the folder storage means for developers to download, Maven central repository on its own, we can click the following address to query the warehouse component https : //mvnrepository.com/ .

 

2.3 Maven member download order

       When looking for members based on Maven coordinates, it will give priority to local warehouse to see if there is a local warehouse this component is used directly; if the local repository does not exist this component, or need to see if a newer component version, Maven will go to a remote warehouse find, found the required components, download it to a local re-use.

 

3 Maven PW

The concept 3.1 Maven PW

  PW is a special remote repository, in order to save bandwidth and time, most companies will choose to set up a private warehouse in the LAN server, with its agents all external remote repository. Internal project can also be deployed on private servers for other projects. When downloading Maven member, it requests the PW, PW when this member does not exist, from the remote repository to find Maven and stored in PW, PW request for download from the member. In addition, some can not be downloaded from an external warehouse to members but also from local PW uploaded to the warehouse for everyone to use. The following example is given in FIG.

   

 

3.2 PW established benefits

3.2.1 save bandwidth

  After the establishment of PW organization can reduce their spending, a large number of repeat requests for external warehouse will consume a lot of bandwidth, the use of external agents PW warehouse, repeat download external components will be eliminated, namely to reduce the pressure outside the network bandwidth.

3.2.2 accelerate Maven build

       Keep the connection request external warehouse is very time-consuming, but Maven some internal mechanisms (such as snapshots check for updates) requires constant checking remote Maven repository while performing building. Therefore, when the project is well equipped with a remote repository, build speed will be greatly reduced. Use PW can solve the problem, Maven just check the LAN PW data, project build speed improved.

3.3.3 deployment of third-party components

       When a member is unable to obtain from any external remote repository, how do? After the establishment of PW, users can deploy these artifacts to the repository, Maven project for internal use.

3.3.4 improve stability, enhanced control

       Maven build highly dependent on a remote repository, therefore, when the external network connection is unstable (such as a corporate network problems, unable to connect remote repository need maintenance, etc.), Maven build will become extremely unstable, unable even to build the project successfully. After the establishment of PW, even if temporarily no external network connections, because the PW in a large number of components has been cached, Maven can still build the project properly. Other PW software provides many additional features, such as rights management, and other distinguishing version, administrators can perform some more advanced control of the warehouse.

 

4 build Maven PW

4.1 Select the build tool

  PW Maven build tool, there are three: Archiva Apache Foundation, JFrog of Artifactory and Sonatype's Nexus. Archiva which is completely open source, so I recommend this software to set up private servers.

 

4.2 JDK download and install

  Archiva application requires the user to start pre-installed jdk, jdk about the download and installation are not described in this article, the reader self-Baidu.

 

4.3 Archiva download and install

       Click the following address into its official website address: http://archiva.apache.org/index.cgi , find the page "Download Archiva" button and select the zip file for download, as shown below:

 

 

 

 

 

      

  Once downloaded unzip the file, which will be "apache-archiva-xxx" folder into a disk directory under which the port folder conf folder in the directory "jetty.xml" can set the application to start the root specific settings please Baidu.

 

4.4 Start Service

(1) using the "Run as administrator cmd" (annex to the Start menu), enter the software installation directory bin directory;

  C:\Windows\system32>cd D:\Program Files\apache-archiva-2.2.1\bin

  C:\Windows\system32>D:

(2) Enter the command "archiva.bat install", the command will run normal output "wrapper | Apache Archiva installed.";

  E:\Program Files\apache-archiva-2.2.1\bin>archiva.bat install

  wrapper | Apache Archiva installed.

(3) Enter the command "archiva.bat start", the command will run normal output "wrapper | Starting the Apache Archiva service ..., wrapper | Apache Archiva started.";

  E:\Program Files\apache-archiva-2.2.1\bin>archiva.bat start

  wrapper | Starting the Apache Archiva service...

wrapper | Apache Archiva started.

 

4.5 Access Services page

  Open your browser and enter in the address bar HTTP: // host: port (the specific host and port user-specified), go to the software management GUI page, the first visit, the user can create an administrator account.

 

 

  After the user logs in successfully, the page on the left menu bar, set out the full functionality of the software menu, the user can perform configuration as needed. The configuration instructions on Archiva, the reader is self-Baidu.

 

 

 

 

 

4.6 download and upload component

4.6.1 download component

4.6.1.1 Configure the local Maven's settings.xml

(1) configuration information with the authentication server

In <servers> a new <server> tag, a new sub-label <id> tag in which, <username>, <password>, where id is the name of the server to be authenticated may be a plurality of label. It is used to mark the server, to the sole; username and password are required for user name and password PW server. If you want to connect multiple PW may be a plurality of similarly configured server, each server is a PW authentication information.

PW information (2) arranged to be connected

Create a <mirror> tag in <mirrors> tag in the tag new child tag <id>, <mirrorOf>, <name>, <url>, where id is marked PW map, the mark to the same server in Like id, if Sifu connection requires authentication information, Maven can find the corresponding server by id, authentication with the authentication information server; mirrorOf value is set to "*", which matches all remote repository, name for the name PW warehouse , free to take, facilitate their own memory and understanding like; url address for the PW warehouse url, is http: // host: port / repository / repository id (this value is the default value, the user can modify);

 

 

 

4.6.1.2 Maven project

  With the above configuration of the Maven settings.xml tool to create a Maven project, then add no difference between dependence and before the addition of the way, so far, PW set up is completed and ready to use.

4.6.2 upload component

4.6.2.1 Configuring Maven pom file project

       In the project tag, add <distributionManagement> tag, specify the destination (PW) to be published. Details are as follows:

<distributionManagement>

    <repository>

    <id>archivaServer(仓库id)</id>

    <url> HTTP: // localhost: 8080 / Repository / Internal (Warehouse address) </ url>

    </repository>

    <snapshotRepository>

        <id>archivaServer(仓库id)</id>

        <Url> http: // localhost: 8080 / repository / snapshots (Warehouse address) </ url>

    </snapshotRepository>

</distributionManagement>

 

  The above information is configured with two warehouses url, it is a repository; the other is a snapshot repository. In each repository has a url.

 

4.6.2.2 Run command issued

       Maven run the deploy command, Maven will automatically compile and package the project, and publish it to PW warehouse. After the release is complete, developers can use the component whim.

 

Guess you like

Origin www.cnblogs.com/yjry-th/p/11672301.html