Use nexus to create a private server

Source: Internet
Author: User
Tags maven central sonatype

The deployment environment is Windows XP.

First download the latest Nexus version from the http://nexus.sonatype.rog/downloads

We can download it as needed. There is a compressed file or war package nexus-webapp-1.9.2.3.war running by other systems such as nexus-webapp-1.9.2.3-bundle.zip.

The nexus-webapp-1.9.2.3-bundle.zip package comes with a jetty container, so we don't need to find another container, you can directly start running.

Bundle installation method:

Decompress the bundle file on the home page and obtain two subdirectories:

Nexus-oss-webapp-1.9.2.3 this directory contains the files required to run nexus, such as startup scripts, dependent jar packages, etc.

Sonatype-work this directory contains the configuration, log files, and repository files generated by nexus. Among them, the first directory is required to run nexus, and the contents of all the Nexus strengths of the same version are the same. The second directory is not required. Nexus dynamically creates the directory during running, but its content is different for each nexus instance, because different users use nexus on different machines with different configurations and repository content. When the user needs this nexus, the default backup sonatype-work/directory, because the directory contains the user-specific content, and the content under the nexus-webapp1.9.2.3 directory is available directly from the installation package.

If you want to start nexus, You need to select the corresponding system version under nexus-oss-webapp-1.9.2.3 \ bin \ JSW \, my environment is: windows-x86-32, so select this directory which contains some scripts as follows:
Installnexus. Bat install nexus as a Windows Service

Uninstallnexus. Bat uninstall the Nexus Windows Service

Startnexus. bat start the Nexus Windows Service

Stopnexus. Bat stop the Nexus ipvs Service

Pausenexus. Bat pause the Nexus Windows Service

Resumenexus. Bat resume the suspended nexus ipvs Service

If you do not want to use these scripts every time you start them, you can configure them as the widnwos service and enable them automatically upon startup.

 

It is also very convenient to start nexus on Linux systems, such as the unbuntu 32-bit system, then you just need to enter the nexus-oss-webapp-1.9.2.3 \ bin \ JSW \ linux-x86-32 and then run the following command:

$./Nexus Console

The command line output is displayed. You can use ctril + C to stop nexus.

In addition to the console, the Linux script of nexus also provides the following commands:

./Nexus start: Start the Nexus service in the background

./Nexus stop: Stop the Nexus service in the background

./Nexus status: view the Nexus service status in the background

./Nexus restart: restart the Nexus service in the background.

 

The default port number of the nexus bundle is 8081. If you start the service, you can access the Port:

Http: // localhost: 8081/nexus

A port conflict may occur when the bundle is started, or you can open it when you want to change the port: nexus-oss-webapp-1.9.2.3 \ conf \ plexus. in the properties file, find the property: Application-port is changed to the corresponding port according to your needs. I changed the property to 4040.

At this time, the address should be as follows: http: // localhost: 4040/nexus

Install nexus in war mode

This war package supports mainstream web containers, such as Tomcat, classfish, Jetty, and resin.

For example, Tomcat puts the downloaded war in the webapps directory and then runs tomcat. Take a look at Tomcat information.

 

Log on to nexus

Default nexus administrator username and password: admin/admin123

Introduction to nexus built-in Repository

Maven gentral: this cruel proxy is the maven central repository, and its policy is release. Therefore, only the release component in the central repository is downloaded and cached.

Release: This is a type repository of the host whose policy is release. It is used to deploy release component within the Organization.

Snapshots: This is a snapshot repository of the host type used to deploy snapshot version components within the Organization.

3rd party: This is a host type repository with the release policy. It is used to deploy third-party release components that cannot be obtained from the public repository.

Apache snapshots: This is a snapshot agent repository used to represent snapshot version components of the Apache Maven repository.

Codehaus snapshots: This is a proxy repository with a snapshot policy. It is used to represent the snapshot version component of the codehaus Maven repository.

Google Code: This is a release agent repository used to represent the release component of the Google Code Maven repository.

Java.net maven2: This is a release agent repository used to represent the release component of the java.net Maven repository.

Public repositories: this repository group aggregates all the repositories whose policies are release and provides services through consistent addresses.

Public snapshot repositories: this repository group aggregates all the above policies as the snapshot repositories and provides services through consistent addresses. (This option is not available in nexus-oss-webapp-1.9.2.3 versions)

Nexus repository classification concept

Maven can download the component directly from the host repository; Maven can also download the component from the agent repository, and the agent repository will download and cache the component from the remote repository. Finally, for convenience, maven can download components from the repository group, but the repository group does not have actual content. It will switch to the host warehouse or agent warehouse it contains to obtain the content of the Municipal component.

Create a nexus host Repository

To create a repository, click the repositories link in the left-side Navigation Pane, select add on the right-side pane, and select hosted Repository from the drop-down menu. The configuration interface shown in figure is displayed:

Enter the repository ID repostory ID, repository name, and repository type respository type. Select the default maven2 repository as the provider, then, the repository policy reader can configure whether the repository is a release version component repository or a snapshot version component repository as needed. Defualt local storage location indicates the no-person storage directory of the warehouse. The field value in the figure is empty. After the Warehouse is created, this value will become a file path based on sonatype-work, such: E: \ nexus-oss-webapp-1.9.2.3-bundle \ sonatype-work \ nexus \ Storage

The default address is the repository storage directory address.

Access setting group

The deployment policy is used to configure the deployment policy of the Repository. The options include read-only (deploy prohibited), disabled redeployment (the same component can only be deployed once), and allowed redeployment.

Allow file browsing indicates whether to allow browsing of repository content

Include in search indicates whether to index the repository and provide search

Publish URL is used to control whether services are provided through URLs. If false is selected, the http404 not found error is returned when the repository address is accessed.

Not found cache TTL indicates the time when the nonexistent information is cached when a file is not found. Take the default value of 1440 minutes as an example. If a file does not exist, then in the next 1440 minutes, if nexus gets the file request again, it will directly return the information that does not exist, instead of looking for a location system.

 

Create a nexus proxy Repository

 

The operation is similar to creating a host repository. When the value of the primary repository type is changed to proxy, you can see the following:

For the agent repository, the most important thing is that the remote repository address is

Remote storage location. You must enter a valid value.

Download remote indexes indicates whether to download the index of the remote repository.

The Checksum policy is used to configure a policy for validation errors. You can ignore the policy, record warning information, or reject downloading.

Authentication when the remote repository requires authentication, the authentication configuration here can be used.

Artifact Max age: the Maximum Cache Time of the component. For the snapshot version, the default value of artifact Max age is-1, indicating that the component is saved after mixed storage and is not re-downloaded, for the snapshot version, the default value is 1440 minutes, indicating that every

Maximum Metadata File Cache Time in the metadata Max age Repository

HTTP request setting and override HTTP Proxy setting. The former is used to configure the HTTP request parameters when nexus accesses a remote repository, and the latter is used to configure the HTTP Proxy

Create a nexus repository Group

To create a repository group, follow these steps:

The information in the configuration is the same as that in others. There is no release or snapshot in the repository group, which is different from the host repository and the agent repository. On the configuration page, you can select a repository in nexus and aggregate it into a virtual repository Group. Note, the order of the warehouses contained in the repository group determines the order of the warehouses contained in the repository group. Therefore, it is best to place the commonly used warehouses in front. When users download components from the repository group, you can quickly access the warehouse containing components.

Nexus index and component search

To search for the maven central database, you must first set the maven central agent repository in nexus to download the remote index. For example:

Set the download remote indexes attribute to true. The default value is false.

If it is true, it is enabled. If it is false, it is disabled because the content of the central repository is large, so the index file is large. You need to check the download information. After clicking the scheduled tasks link in the left-side navigation bar of the interface, you can see that the status of the system scheduled task is runing. After the download is completed, the task disappears.

Scheduled tasks interface:

Configure Maven to download components from nexus

When you need to add a public repository on the nexus private server to the project, you can configure the code in the project Pom. xml file as follows:

<project>

<repositories>
<repository>
<id>nexus</id>
<url>http://http://localhost:4040/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://localhost:4040/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>

</project>

This configuration is only valid for the current Maven project. In actual application, we often want to complete the configuration once so that all Maven projects on the local machine can use their own Maven private server. The setting. XML code for configuring the local repository is as follows:

<settings>
  
   <mirrors>

<mirror>
<id>central</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:4040/content/groups/public/</url>
</mirror>
</mirrors>  

<profiles>
     <profile>
<id>JDK1.6</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.6</jdk>
</activation>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>central</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>central</activeProfile>
<activeProfile>JDK1.6</activeProfile>
</activeProfiles>
</settings>


Use Maven to deploy components to nexus

The Snapshot version components generated by daily development can be directly deployed to the host repository with a snapshot in nexus. The components officially released by the project should be deployed to the host repository with a release in nexus. The configuration of POM. XML is as follows:

<project>
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Releases Repository</name>
<url>http://localhost:4040/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshots Repository</name>
<url>http://localhost:4040/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>


The Nexus repository is read-only for Dawn users. To deploy components, you also need to configure the authentication information code in setting. XML as follows:

<servers>

<server>
<id>releases</id>
<username>admin</username>
<password>iapppay</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>iapppay</password>
</server>
</servers>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.