Maven and antx (sorting)

Source: Internet
Author: User
Tags maven central

I. MAVEN and antx Overview:

Introduction to antx

Before talking about why Maven is used, I would like to explain that antx, many people know ant. In fact, antx is a set of ant extension-based tools developed by Alibaba in some ways similar to mavnen, we even have the eclipse antx plug-in. We can imagine that antx plays an important role in Alibaba's project management. It has many advantages:

1. better support for the second Library

2. Support dependencies and inheritance between projects

3. You can use jelly to write plug-ins for antx.

4. Support the car package. Here we will briefly introduce the car package:

A car is an intermediate format of a war package. It contains VM pages, webx. XML, classes, and other resources during packaging, but does not contain
WEB-INF/lib, a war package can contain multiple car package, when the war package, can put the web project dependent car jar
Package, including the jar package for passing dependencies, merged to WEB-INF/lib together

5. auto config: resources to be replaced in the auto-config.xml configuration project

 

Why introduce Maven?

 

First, let's talk about what problems antx has:

1. the management of third-party libraries in antx is complicated. If a project requires a new jar package or a new version of jar package, you must follow a strict application process and submit the relevant jar package by yourself.

2. antx has no tool support for jar package version control and changelist. As a result, many projects use 1.0-Snapshot from the beginning to the end, which makes the package version difficult to control.

3. antx does not support SCM packaging and deployment very well.

4. antx has problems with IDE compatibility. To enable eclipse to support antx, We need to write an antx plug-in separately to enable eclipse to support antx. For other good ides such as intellij idea, does not support antx.

5. Many ide now have one-click debug functions, including integration support for application servers. antx is insufficient in this regard.

 

Can Maven solve these problems? Is there a better advantage? The answer is yes.

1. The Maven library is maintained by an open-source organization. We don't need to worry about third-party libraries any more, even if we maintain them ourselves, it is more convenient.

2. MAVEN provides tool support for Version Management of jar packages. For example, separating the release and snapshot versions is conducive to SCM management.

3. MAVEN is a standard and has many users and does not require additional training.

4. There are many plug-ins in Maven, which can provide more functions. The existing Maven system is relatively open, and the technologies used are relatively general and mature. The plug-in mechanism can also help us expand more functions.

5. Download the maven library is out-of-the-box, and you do not need to implement all down operations. The Maven plug-in is also automatically upgraded, which is convenient.
We expand new features.

6. It can be easily integrated with mainstream ide such as Eclipse and idea.

7. repository Manager: it has two purposes: first, its role is a highly configurable proxy between your organization and the Public Maven repository, secondly, it provides a place for your organization to deploy components generated within your organization (second-party library.

8. Version Management function. Version Management here is not the version management of a third-party library, but the version management of a project.

9. site function: the emergence of this function allows us to clearly view the project status, and automatically publish the project status and various reports to the Intranet or external network in the form of sites, you can view the project status anytime, anywhere. There are many reports that can be selected, including Doc generation,CodeStandard Check, automatic bug check, unit test report, unit test code coverage report

 

2. Relationship between Maven and antx:

1. Manage antx repository to Maven Repository Antx uses SVN to manage the second-party and third-party libraries. MAVEN also uses third-party tools. Currently, the popular repository management software is nexus, which is managed through Maven repository, we can manage both third-party databases and the second-party database and even the snapshot database. Why do we need to build a local repository? Of course, you can use a remote Maven repository to obtain the jar you need, but creating a local repository is more efficient and more conducive to our management, after we establish such a unified repository locally, even throughout the company and the group, we no longer need to store all the jar packages on the local development machine, through Maven, we can use simple commands to publish our second Library to the Repository Manager. Snapshot is a temporary version. Maven can manage it like other release versions. It is quite valuable when two modules depend on development, this will be described in detail in "version management. 2. Convert the second library and third-party library of antx to the maven repository. 1) release the second Library to the maven repository. 2) third-party libraries, such as Apache log4j. jarmaven automatically downloads the file from the maven central repository. 3) switch the module. XML to Pom. XML: Maven only needs one or more pom files based on the number of modules. We need to convert the corresponding dependencies in Maven format according to the dependency. 3. From project. XML to Pom. xml
Antx uses project. XML is used to describe the basic information of a project, such as dependency and structure. jelly describes the project objectives, such as default = "jar", which indicates the project. the default objective of XML is to generate a jar package. antx calls different ins based on the project objectives. Maven2.0 no longer supports Jelly's functions. MAVEN uses lifecycle to replace the default Goal concept in jelly. MAVEN defines some standard lifecycle for project construction, which is simple to list, for example, it can be divided into validate-> initialize-> compile-> process-reslources-> test-comile-> process-test-resources-> test-> package-> install-> deploy Maven if the plug-in needs to be implicitly executed, you need to bind the plug-in to a stage of lifecycle. For example, we want to synchronize the content of AutoConfig to antx. properties. we can write a plug-in and bind it to the lifecycle of initilize, and synchronize AutoConfig to antx according to the existing policy of antx. properties, while in install phase, AutoConfig will according to antx. in the properties configuration war, ear, or VM template in jar, press antx. properties configuration item to generate the actual value. Possible problems:
1) convert the dependencies between the two-party library and third-party library in project. XML to the dependencies in Maven repository. Dependencies between libraries can be directly converted according to the rules defined by the user. dependencies between libraries on third-party libraries are troublesome, and some must be manually processed. 2) use different plug-ins to implement the content in the jelly script. 3) Some jar files in some third-party libraries have been modified. Such dependencies need to be manually uploaded to our artifactory and then processed for dependencies. 4. Dependency Management Problems 1) dependency and inheritance in Maven
Maven and antx have similar ideas, so they support project dependencies and inherited functions. A common practice in Maven is to define a parent pom, which defines common plug-ins, the address of the maven library, the address of the deployed target library, and the validate whitelist. The project's master control file inherits from this parent pom, which simplifies the configuration of the project. 2) Dependency conflicts • Dependency conflicts do not need to be concerned. For example, two open-source third-party libraries reference different log4j versions, because the new version of log4j is compatible with the old version. We can think that such dependency conflicts can be automatically resolved.
• We are also concerned about this, such as ice 3.1 and 3.2. The new version changes the TCP connection mode to short connections. If such dependency is upgraded, it must pass strict tests, only stress tests can be used to agree to the upgrade.
To solve this problem, we can create a plug-in that checks the version dependency. Only the dependency check can be used to package and release the plug-in. We will configure a whitelist in the parent Pom. Only the jar packages specified in the whitelist, such as log4j and commonlogging, can pass the check even if there is a conflict. If there is no conflict in the whitelist, we will report a detailed error message. Now, the maven Eclipse plug-in can graphically express dependency and dependency conflicts, this helps us solve conflicts. The modification permission of the parent Pom is assigned to the SCM or technical director. Only the building version number can be specified forcibly. If a version conflict occurs, the developer must specify the version number forcibly, it can be built only through SCM or technical owner modification. At least be aware of the mandatory designation of dependency conflicts. For example, if refund-domain depends on Mina-core 1.1.5, and policy-client depends on 1.2.3, the conflicting dependencies are marked with red arrows. If Mina is not in our whitelist, so this build will not succeed. 5. How does Maven support Jelly's functions?
Maven does not support jelly, but the same functions can be achieved through plug-ins. Currently, jelly in antx can be used in the following scenarios:
• (1) Specify the default goal in project. Jelly, such as jar, ear, and car. During reactor execution, different plug-ins will be called for Packaging Based on defagogoal. Maven can have a corresponding concept packaging, which can implement the same functions. Packaging is different. In the maven package stage, Maven also calls different plug-ins to implement the packaging function.
• (2) some jelly implemented some copy file functions in the deployment phase. I can see that the jelly files in trademanager and Denali are both deployed, for example, copy the key file from a local file to the project and package it. The reasource plug-in Maven can implement the same functions. For example, copy external resource files to the target/class directory and package the files. If there is another jelly plug-in implementation, 6. How does Maven support AutoConfig? In auto-config, the path of the resource file requiring filtering is listed in script. In Maven, the resources plug-in is used to perform this task. You need to include it in POM. xml. 3. Install Maven Maven: Http://maven.apache.org/download.html Preparations: JDK or later, you need to set java_home in your operating system Windows 2000/XP 1. decompress the apache-maven-2.0.10-bin.zip to the directory you want, such as C:/Apache, then the decompressed directory is C:/Apache/apache-maven-2.0.102. add the environment variable m2_home to your system, as shown in the example in step 1, the value of the environment variable m2_home is C:/Apache/apache-maven-2.0.103. add the environment variable m2 to your system. The value is % m2_home %/bin4. (Optional). The optional environment variable maven_opts. For example, if you want to change the Java heap (HEAP) you can set the value to-xms256m-xmx512m. This option is very useful in some cases, when you use MVN site to generate a site, the heap size is relatively large. In this case, you may need to set this value. The default heap size for Java startup is 64 MB. 5. add m2 to the path. In this way, In command line mode, you can use mvn6. you need to set java_home7. Open a command line client and run MVN-version. if the version number is displayed, congratulations, the installation is successful. UNIX-based operating systems (Linux, Solaris and Mac OS X)

 

1. decompress the apache-maven-2.0.10-bin.zip to the directory you want, such as/usr/local/Apache-Maven, then the decompressed directory is/usr/local/Apache-Maven/apache-maven-2.0.102. export m2_home =/usr/local/Apache-Maven/apache-maven-2.0.103.export m2 = $ m2_home/bin4. (optional) Optional environment variable maven_opts, for example if you want to change Java heap (HEAP) you can set the value to-xms256m-xmx512m. This option is very useful in some cases, when you use MVN site to generate a site, the heap size is relatively large. In this case, you may need to set this value. The default heap size for Java startup is 64 MB. for example, export maven_opts = "-Xms256m-xmx512m" 5. Export Path = $ M2: $ path6. set java_home7. Run MVN-version. if the version number is displayed successfully, congratulations, the installation is successful. 4. Install Maven in eclipse

InEclipseUseMaven
Using Maven in eclipse is implemented through the plug-in named m2e. before talking about how to use it, Let's briefly talk about the features of m2e:

    1. Check out a project from SCM
    2. Use predefined archetype to create a project
    3. Create a Maven Module
    4. Import Maven Project
    5. M2eclipse has the POM editor, so you do not need to manually edit the Pom.
    6. M2eclipse built-in search function for central Maven Repository
    7. The dependency tree function allows you to conveniently view dependencies between jar packages.

With these features, you can easily start developing your Maven project in eclipse Without tedious commands. Just click the wizard step by step.

InstallM2e 

In eclipse, select software updates from the Help menu. In the software updates and add-ons dialog box, click the available software button, and then click Add site add Update site URL: http://m2eclipse.sonatype.org/update. After you add this URL, you will be able to add Maven integration, Maven optional components, and Maven project configurators to your project.

SlaveMaven ArchetypeCreateMavenProject 

Maven Archetype is a project template. The Maven repository contains many archetype, includingProgramTo almost all types of Message Components. With m2eclipse, it is very easy to use Maven archetype. To create a Maven project using Maven archetype, select File> New> project... And then input Maven in the filter field. Select a new Maven project and click Next. The next screen provides an interface for you to select the maven archetype for the new project.

 

Search for dependencies and components

 

Quick Searching and locating of Dependencies from the maven repository can greatly save time. With m2eclipse, you no longer need to find a central repository for components of a version. If you need to add a component to the maven project, right-click the project and select Add dependency under the maven menu. Then, you will see the dialog box as shown in. Simply entering groupid and artifactid will allow m2eclipse to search for the Nexus index of a Maven repository and display matched components. Quick component Locating means that you no longer need to spend countless times in the maven repository to find a specific dependent component.

Analysis dependency tree 

M2eclipse provides some interesting functions for you to analyze and draw charts on Project dependencies. You can click the project Pom. XML to load the POM editor. If you open a project with many dependencies, you can click the dependency tree Tab Of the POM editor and see the dependency display.

If you want to view dependencies in graphs, click the dependency graph tab to view the project dependency graph. Click a node in the figure to highlight the node and emphasize the relationship between the component and other components in the project dependency.

 

From: http://blog.csdn.net/ghost_t/article/details/5709640

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.