Maven and Antx (finishing)

Source: Internet
Author: User

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

I. MAVEN and ANTX Overview:

Antx Introduction

Before I talk about why I use MAVEN, I want to say, Antx, a lot of people know ant, actually Antx is a set of ant-based extensions that are similar to Mavnen in some ways, and we even have Eclipse's Antx plugin, It is conceivable that Antx has an important position in the project management of Ali. It has a lot of good places:

1. Can be relatively good support for second-party libraries

2. Support for dependencies and inheritance between projects

3. Antx can use jelly to write plugins

4. Car package support, here is a brief introduction to the car bag:

Car is an intermediate format for a war package that contains resources such as VM pages, webx.xml,classes, and so on when packaged, but does not contain
Web-inf/lib, a war package can contain multiple car packages that, when packaged in a war package, enable the jar in the car that the Web project relies on
packages, including pass-dependent jar packages, merged together into Web-inf/lib

5. Auto Config:auto-config.xml resources that need to be replaced in the configuration project

Why to introduce Maven

First of all, what are the problems with Antx?

1. Antx management of third-party libraries is more complex, if a project requires a new jar package or a new version of the jar package, you need to go through a strict application process, and you need to submit the relevant JAR package

2. Antx to the jar Package version control, Changelist and so on without tool support, resulting in a lot of projects are 1.0-snapshot from the beginning to the tail, resulting in the package version is not very control.

3. Antx support for SCM Packaging deployment is not very strong.

4. Antx there is a problem with the IDE's compatibility, in order for Eclipse to support Antx, we need to write a antx plug-in to let Eclipse support Antx, and for some other good ides such as IntelliJ idea, Antx is not supported.

5. Many Ides now have one-click Debug functionality, including integration support for application servers, and there are antx in this area.

Can maven solve these problems, and have a better advantage, the answer is yes

1. Maven's library is maintained by the Open source organization, and does not require us to spend more time on third-party libraries, even if we maintain them, it is more convenient.

2. MAVEN has tool support for version management of jar packages, such as separating release and snapshot versions to facilitate SCM management.

3. MAVEN is a standard, with a lot of people and no additional training required.

4. Maven has more plugin, can have more features, MAVEN's existing system is more open, the technology used is relatively generic and mature, plugin mechanism can also facilitate us to expand more features.

5. Maven's library download is ready-to-use, without the need to implement all down. MAVEN's plug-in is also automatically upgraded to facilitate
We extend the new functionality.

6. It's easy to integrate with the mainstream IDE, such as Eclipse, idea

7. Warehouse Manager: It appears for two purposes: first its role is a highly configurable proxy between your organization and the public Maven repository, and secondly it provides a place for your organization to deploy the artifacts generated within your organization (second party libraries).

8. Version management features, where versioning is not the version management of a third-party library, but the version management of the project

9. Site function: its appearance allows us to see the status of the project at a glance, you can automatically put the status of the project and a variety of reports in the form of a site to the intranet or the external network, you can view the status of the project anytime and anywhere. There are a number of reports that can be selected, including, Doc generation, code specification checking, automatic bug checking, Unit test report, Unit test Code Coverage report

Two. Relationship between Maven and Antx:

1. Antx Warehouse to MAVEN warehouse managementAntx is managed by SVN to manage second-party libraries and third-party libraries, MAVEN is also through third-party tools to achieve, the current more popular warehouse management software is Nexus, through the MAVEN warehouse management, we can not only the third party library Unified Management, You can also manage the second-party library or even the snapshot library. Why do we have to build a local repository, of course you can get the jar you need through a remote Maven repository, but to build a local warehouse is more efficient, more conducive to our management, we are locally, and even the entire company, the group established such a unified warehouse, We no longer need to have all the jar packages in the local development machine, and through Maven we can publish our second-party library to the warehouse manager through a very simple command. Here's a brief SNAPSHOT, in short, SNAPSHOT is a temporary version, MAVEN can manage it just like any other release version, and it's quite valuable when two modules are dependent on development, which I'll describe in detail in the version management article.2. Convert Antx's second-party libraries and third-party libraries to the MAVEN repository1) Release the second-party library to the MAVEN Repository 2) third-party libraries, such as Apache's log4j.jarmaven will automatically download from MAVEN's central repository 3) convert Module.xml to Pom.xml, MAVEN requires only one or more pom files depending on the module, and we need to transform the dependency in MAVEN format according to the dependency relationship.3. From Project.xml to Pom.xml
Antx uses Project.xml to describe the project's basic information, such as dependencies, structures, etc., using project.jelly to describe the project's goals, such as the default= "jar", which indicates that the default goal of this project.xml is to generate a jar package, Antx calls different plug-ins according to the project target. Jelly is no longer supported in Maven2.0, MAVEN uses binding lifecycle to replace the concept of default goal in Jelly, and Maven constructs a project that defines some standard lifecycle, simple enumeration, such as validate- >initialize->compile->process-reslources->test-comile->process-test-resources->test-> Package->install->deploy maven plugins need to be bound to a phase of lifecycle if they need to be executed implicitly. For example, we want to synchronize the contents of AutoConfig to antx.properties, we can write a plugin and bind it to the initilize life cycle, antx the existing policy to synchronize AutoConfig to Antx.properties, while the install Phase,autoconfig will generate the actual values according to the Antx.properties configuration item based on the Antx.properties configuration war,ear, or the VM template in the jar.Possible problems:
1) Convert dependencies in Project.xml to two-party libraries and three-party libraries to dependencies in Maven repository. The dependence on the two-party library can be transformed directly according to the rules of its own definition, and the conversion dependence of the three-party library is troublesome and some need to be handled manually. 2) use different plugins for the content in the jelly script. 3) Some of the jars in the three-party library have been modified by us, which require manual processing to upload to our artifactory and then handle their dependencies.4. Dependency management issues1) Dependencies and inheritance in Maven
The ideas of Maven and Antx are similar, so the dependencies and inherited functions of the project are supported by them all. A more common practice in Maven is to define a parent POM, which defines common plugins, the address of the MAVEN library, the target repository address of the deployment, the validate whitelist, and so on. The master file for the purpose, inherited from this parent POM, can simplify the configuration of the project.2) reliance on conflict issues• A dependency conflict is not a concern, such as two open-source three-way libraries, referencing different log4j, because the new version of log4j can be compatible with the old version. We can assume that such a dependency conflict can be resolved automatically.
• The other is our concern, such as ice 3.1 and 3.2, the new version changes the TCP connection to a short connection, and if this dependency is upgraded, it must pass rigorous testing, including stress testing, to agree to the upgrade.
The solution to this problem is that we can make a plug-in that checks for version dependencies, which must be checked to package the publication. We will configure a whitelist in the parent Pom, only the jar packages indicated in the whitelist, such as log4j,commonlogging, can be checked even if there is a conflict. If there is no conflict in the whitelist, we will report detailed error messages, and now Maven's Eclipse plugin has been able to graphically show dependencies and dependency conflicts so that we can resolve conflicts. The modification of the parent Pom will be given to the SCM or the technical owner, only they can force the designation of the build version number, if the developer encounters a version conflict need to enforce the specified version number, must be modified by SCM or technical owner to be able to build through. It is at least a well-defined idea to enforce a dependency conflict. For example, Refund-domain relies on Mina-core 1.1.5, and Notify-client relies on 1.2.3, which will use Red arrows to mark conflicting dependencies, and if Mina is not in our whitelist, then this build will not be successful.5. How MAVEN supports the Jelly feature
MAVEN does not support jelly, but the same functionality can be done through plugins. The jelly usage scenarios now in ANTX are:
• (1) Specify the default goal in project.jelly, such as Jar,ear,car, when the reactor is executed, it will be packaged according to the Defaultgoal call different plugins. Maven can have a corresponding concept packaging that can achieve the same functionality. Packaging, in the MAVEN package phase, MAVEN will also invoke different plugins to implement the packaged functionality.
• (2) Some jelly implemented some copy files in the deployment phase, and I looked at the jelly files in Trademanager and Denali, all at the time of deployment, such as copy the key file from one place to the project and then package it. The Reasource plugin in Maven can do the same thing, such as copy an external resource file to the Target/class directory, then package it, and if there's a jelly plug-in implementation,6. How does maven support AutoConfigThe path to the resource file that needs to be filtering is listed in the script in Auto-config, and Maven uses the resources plugin to do this, and it needs to be included in the Pom.xml.three. Maven InstallationMaven:Http://maven.apache.org/download.htmlpreparatory work:JDK1.4 above, you need to set java_home in your operating systemWindows 2000/xp1. Unzip the apache-maven-2.0.10-bin.zip to the directory you want, such as C:/apache, then the extracted directory is c:/apache/apache-maven-2.0.102. Add the environment variable m2_home to your system, and 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 with a value of%M2_HOME%/BIN4. (Optional) Optional environment variable maven_opts, such as if you want to change the size of the Java heap (heap) then you can set its value to:-xms256m-xmx512m, this option is very useful in some cases, during the actual operation, when you use MVN Site generated at the time of the heap size will be larger, this time you may need to set this value, Java startup default heap size is 64m.5. Add M2 to path, so you can use MVN6 in command-line mode. You need to set Java_home7. Open a command line client, run Mvn–version, if the version number successfully appeared, then congratulations, the installation is successful.unix-based Operating Systems (Linux, Solaris and Mac OS X)

1. Unzip the apache-maven-2.0.10-bin.zip to the directory you want, such as/usr/local/apache-maven, then the extracted 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= $M 2_home/bin4. (Optional) Optional environment variable maven_opts, such as if you want to change the size of the Java heap (heap) then you can set its value to:-xms256m-xmx512m, this option is very useful in some cases, during the actual operation, when you use MVN Site generated at the time of the heap size will be larger, this time you may need to set this value, Java startup default heap size is 64M. For example: Export maven_opts= "-xms256m-xmx512m" 5.export path= $M 2: $PATH 6. Set Java_home7. Run Mvn–version, if the version number successfully appears, then congratulations, the installation is successful.four. Install maven under Eclipse

in the Eclipse under Use Maven
Using Maven under Eclipse is done through a plugin called m2e, and before saying how to use it, let's briefly say what the M2E features are:

    1. Check out a project from the SCM
    2. Create a project with pre-defined archetype
    3. Creating a Maven Module
    4. Importing Maven Projects
    5. M2eclipse has POM Editor, can not manually edit Pom
    6. M2eclipse built-in search capabilities for central Maven repositories
    7. Dependency tree function, easy to view, dependencies between jar packages

With these features, you can easily start developing your Maven project in Eclipse, with no cumbersome commands, and follow the wizard step-by-click.

installation m2e

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 to update the sites Url:http://m2eclipse.sonatype.org/update / 。 After you add the URL, you will be able to add Maven integration, MAVEN Optional components, and MAVEN project Configurators for your project.

from Maven archetype Create a Maven Project

Maven archetype is a project template, and the Maven repository contains many archetype, including almost all types of projects from Web applications to messaging components. With M2eclipse, using Maven archetype becomes very easy. To create a MAVEN project using MAVEN archetype, select Project ..., file-New, and then enter MAVEN in the filter field. Select the new MAVEN project and click Next. The next screen will provide an interface for you to select the Maven archetype for the new project.

   

Search dependencies and artifacts

Fast Search and location dependencies from the MAVEN repository can save you time. With M2eclipse, you no longer need to find a central repository for a version of the widget. If you need to add a widget to your Maven project, right-click on the project and select Add Dependency under the Maven menu. After that, you'll see a dialog box like this. The simple input groupid and Artifactid will let M2eclipse search a maven repository's Nexus index and display matching artifacts. Quickly locating widgets means that you no longer have to spend countless hours in the Maven repository to find a specific dependency component.

Analyze Dependency Trees

M2eclipse provides some interesting features for you to analyze and plot the diagrams that your project relies on. You can load the Pom Editor by clicking on the Pom.xml of the project. If you open a project with a lot of dependencies, you can click on the Dependency Tree tab of the Pom editor and see the dependency display.

If you want to view dependencies as graphs, click the Dependency Graph tab to view the project dependency graph. Clicking on a node in the graph illuminates the node and emphasizes the relationship between the component and other artifacts in the project dependencies.

Maven and Antx (finishing)

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.