MAVEN Warehouse-building LAN (Windows edition)

Source: Internet
Author: User
Tags jboss

Use Nexus to build a LAN. Recognize the role of MAVEN warehouse 1.1 maven Warehouse

When we were building a project with Eclipse's original project skeleton, we often had a Lib folder in the project directory to hold the jar files needed for the project, and a Lib folder each time a new project was built. Then the jar is copied into the Lib folder configuration path, it is clear that there is a lot of duplication of work, and different projects using the JAR package is not the same, we need to slowly distinguish. Then we used project management tools like SVN or git, and we needed to introduce a lot of jar files into the code base, which is not a good thing.
And Maven can help us solve these problems, the MAVEN repository is dedicated to the location of the jar files (can also be used to store project War,zip,pom and other files). Each jar file is assigned a coordinate in the MAVEN repository, such as the jar package for Jstl:

<groupId>javax.servlet</groupId>         Group ID<artifactId>jstl</artifactId>            Build ID ...  The remainder of the properties are described later

In doing so, Maven can easily control the project dependent version. Simply put, the Maven warehouse is helping us to manage project artifacts together.

1.2 Maven Warehouse Categories

Project Construction Query path: First query the local warehouse, not found will query the Central warehouse, can not find the error. The Central warehouse address is:

    1. For http://www.sonatype.org/nexus/Nexus
    2. http://mvnrepository.com/Recommended Use
    3. Http://repo1.maven.org/maven2
      The above three is more common, but also the project is used more, but because the download speed is too slow, and the warehouse jar file is not complete, the actual enterprise development needs us to build a database.
Two. Install using Nexus

Note that there is more than one tool for building a maven. The main version of the blogger is nexus-2.12.0.

    1. Click to download , password: 1ar1
    2. After the download is complete, the decompression is completed to the directory NEXUS-2.12.0-01-BUNDLE\NEXUS-2.12.0-01\BIN\JSW can be seen:
    3. Bo Main computer is 64-bit so open the last folder:
    4. Click on the second BAT file to set the Windows service, turn on Nexus after access URL : http://localhost:8081/nexus/start after opening the following page, that is, the Nexus installation and launch success.
Three. Configure the Maven
    1. Click Login login in the upper right corner, the initial account is admin, password is admin123 login successful can modify the account password, find their own.
    2. Click on the left navigation respositories.

      You can see the default number of warehouses, types of warehouse type meaning:
    • Hosted host repository for the release of components that are not allowed by third parties, such as jar packages for commercial software such as Oracle drivers
    • Proxy proxies remote repositories, such as three Maven remote repositories written above. If some jar files do not exist locally, they will be downloaded to these proxy sites.
    • Release repository for the release module in the releases internal module
    • Snapshots Release the warehouse of the internal snapshot module
    • 3rd party third parties rely on the warehouse, the local upload jar package after use
    • Group warehouse to add additional warehouses for developers to set up
      to start building a database, it's worth noting that MAVEN Project index: MAVEN Project index is a convenient way to find dependent builds on a Web site. So before you set up a setup, you should download the Maven index, about dozens of M:

      To change the download Remote Indexs property to True and click Save, you can view the progress of the download index scheduled tasks in the menu bar.
      3. Add your own proxy remote library, sometimes our project needs to introduce some special jar files, such as some of JBoss's jar package, this time can also proxy the remote warehouse in a database:

      Add a proxy type after clicking Add and fill in the Id,name and URL in turn, so that you no longer need to configure the remote repository in your project:
<repository>    <id>jboss</id>    <name>jboss repository</name>    <url> http://repository.jboss.com/maven2/</url>    <releases>        <updatepolicy >daily</updatePolicy><!--never,always,interval N--        <enabled>true</enabled >        <checksumPolicy>warn</checksumPolicy><!--fail,ignore--    </releases>    <snapshots>        <enabled>false</enabled>    </snapshots>    < layout>Default</layout></repository>

4. The use of the host warehouse, some of the above mentioned special commercial properties related to the jar files, such as the Oracle driver package, Ojdbc.jar does not support remote download, this time can be downloaded from our local jar package to the private.

Note Gav settings to be consistent with your pom.xml, upload and add to artifacts click Upload:

5. The above group type warehouses are required because of the excessive number of the silos, resulting in increased configuration complexity:

Remember to click Refresh, click on a unique group warehouse, click Configure configuration can see just the agent warehouse we manually added, and then add the Agent warehouse to the group warehouse, so rely on, the project needs to configure the URL of the group warehouse can access multiple database.

Four. Local area network using MAVEN 4.1 single project using MAVEN

After the above steps are complete, you can refer to the Pom.xml in the project to change the default download warehouse URL:
Specify the database, my IP is 170, do not copy all

<repositories>      <repository>          <id>nexus</id>          <name>nexus</name>          <url>http://192.168.1.170:8081/nexus/content/groups/public/</url>          <releases>              <enabled>true</enabled>          </releases>          <snapshots >              <enabled>true</enabled>          </snapshots>      </repository>  </repositories>

Specify the plug-in warehouse

<pluginRepositories>      <pluginRepository>          <id>nexus</id>          <name>nexus </name>          <url>http://192.168.1.170:8081/nexus/content/groups/public/</url>          <releases>              <enabled>true</enabled>          </releases>          <snapshots >              <enabled>true</enabled>          </snapshots>      </pluginrepository >  </pluginRepositories>

Once configured, you can download the dependency package from the. However, this can only work in the change project, each configuration item needs to write two times, in order to carry out the lazy mode to the end, we can also specify the global private warehouse.

4.2 Global designated

Find the Setting.xml file in the Maven file

To add a configuration in Setting.xml:
Add under the <profiles> tab

<profile>    <repositories>        <id>central</id>        <name>central</name>        <url>http://192.168.1.170:8081/nexus/content/groups/public/</url>        < layout>default</layout>        <releases>            <enabled>true<enabled >        </releases>        <snapshots>            <enabled>true<enabled>        </snapshots>    </repositories></profile>

Activate profile after configuration.

<activeProfiles>      <activeProfile>central</activeProfile>  </activeProfiles>

This way, all MAVEN projects on this computer download the jar file and access the LAN 170 computer first.
-----------------------------------Windows configuration is complete-----------------------------------
Extension: The meaning of each label in Setting,xml:

1.servers (server)

<servers>    <server>        <id>server001</id>        <username>my_login</ username>        <password>my_password</password>        <PRIVATEKEY>${USR.HOME}/.SSH/ID_DSA </privateKey>        <passphrase>some_passphrase</passphrase>        <filepermissions>664 </filePermissions>        <directoryPermissions>775</directoryPermissions>        < Configuration></configuration>    </server></servers>

The ID is consistent with the Distributionmanagement ID in Pom.xml, and the server identity
Username and password represent the user and password required for server authentication
Privatekey, passphrase a set of keys (not commonly used)
Filepermissions, directorypermissions if a repository file or directory is created at the time of deployment, permissions can be used (not commonly used)
2.mirrors (Mirror)

<mirrors>    <mirror>        <id>planetmirror.com</id>        <name>planetmirror Australia</name>        <url>http://downloads.planetmirror.com/pub/maven2</url>         <mirrorOf>central</mirrorOf>    </mirror></mirrors>

Set up a central warehouse image, look at the warehouse classification, but also a remote warehouse configuration method.
3.profiles (Build environment)
This may be difficult to understand, as the Maven authoritative guide book says:

Profile allows you to customize a particular build for a particular environment;
The two examples of building an environment are the product environment and the development environment. When you work in a development environment, your system may be configured to access a development database instance running on your native, and in a production environment, your system is configured to read data from the product database. MAVEN allows you to define any number of build environments (build profiles) that can overwrite any configuration in Pom.xml.

Simple understanding is that you can first profile in the first component of a good project running environment, such as preset a environment is actually used in development, and in fact, the line is a B environment, then on the line when we do not need to modify the configuration in Pom.xml, only need to activate the change profiles.
4.activation (Activate build environment)

<activation>    <activeByDefault>false</activeByDefault>    <jdk>1.5</ jdk>    <os>        <name>windows xp</name>        <family>Windows</family>        <arch>x86</arch>        <version>5.1.2600</version>    </os>    <property >        <name>mavenVersion</name>        <value>2.0.3</value>    </property> </activation>

Specify when the environment configured in profile starts to take effect
5.activeProfiles (Active profile)

<activeProfiles><activeProfile>env-test</activeProfile></activeProfiles>

The last label in Setting.xml indicates that the profile of Env-test has been activated

The above purely representative blogger personal views, if there is an understanding of errors or questions, please make brick advice.
Resources: Maven's authoritative guide, maven learning (iv) using Nexus to build a maven

MAVEN Warehouse-building LAN (Windows edition)

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.