Introduction to Maven and simple use

Source: Internet
Author: User

The MAVEN Project object Model (POM) is a software project management tool that allows you to manage project builds, reports, and documents with a small description of the information. In addition to its program building capabilities, Maven offers advanced project management tools. Because MAVEN's default build rules are highly reusable, it is common to build scripts with two or three lines of Maven to build simple projects. Thanks to MAVEN's project-oriented approach, many Apache Jakarta projects use Maven, and the percentage of company projects that are MAVEN-based continues to grow. The word maven is derived from Yiddish (Hebrew), meaning the accumulation of knowledge, originally used in the Jakata turbine project to simplify the building process. There were some projects (with their ant build files), with only minor differences, and the jar files were maintained by CVS. So hopefully there's a standardized way to build a project, a clear way to define the composition of the project, an easy way to publish information about the project, and a simple way to share jars across multiple projects. [1] FeaturesEditSo what's the difference between Maven and Ant? Before you answer this question, the first thing to emphasize is that Maven and Ant are two different aspects of building problems. ANT provides cross-platform build tasks for Java technology development projects. Maven itself describes the advanced aspects of the project, which borrows most of the build tasks from Ant. Therefore, since Maven and ant represent two very different tools, the next step is to explain the differences between the equivalent components of the two tools, as shown in table 1. [1]

  
Maven Ant
Standard build File Project.xml and Maven.xml
  
Build.xml
Attribute processing order ${maven.home}/bin/driver.properties${project.home}/project.properties${project.home}/build.properties${ User.home}/build.properties the last definition of a system attribute defined by the-d command-line option determines the function. The system attributes defined by the-d command-line option are handled first by a task-loaded attribute.
Building rules Build rules are more dynamic (similar to programming languages); they are executable XML based on Jelly. Build rules are more or less static, unless you use <script> tasks
Extended language
  
Plugins are written in Jelly (XML). Plugins are written in the Java language.
Build Rule Extensibility The build goal is extensible by defining <preGoal> and <postGoal>. Building rules are difficult to scale, and can be simulated by using <script> tasks <preGoal> and <postGoal> roles.
MAVEN is a project management tool that contains a project object model, a set of standard collections, a Project life cycle (Project Lifecycle), a dependency management system (Dependency Management System), and the logic used to run the plug-in (plugin) target (goal) defined in the life cycle phase (phase). When you use MAVEN, you use a well-defined project object model to describe your project, and maven can apply crosscutting logic that comes from a set of shared (or custom) plug-ins. Maven has a life cycle that is called when you run the MVN install. This command tells Maven to perform a series of sequential steps until it reaches the life cycle you specify. One of the implications of traversing the life cycle journey is that Maven runs many of the default plug-in targets, which complete tasks like compiling and creating a JAR file. In addition, MAVEN can easily help you manage project reports, build sites, manage jar files, and more. Common commandsEditMVN archetype:create Creating a maven project MVN compile compiling source code mvn deploy release project MVN test-compile compiling test source code MVN test run the unit test in the application MVN site build project related Information about the site MVN clean clears the build results in the project directory MVN package installs JARMVN eclipse:eclipse in the local repository based on the JARMVN install generated by the project Build the Eclipse project file Mvnjetty:run start the Jetty service Mvntomcat:run start the Tomcat service mvn clean package-dmaven.test.skip=true: RePack the previous package, Skip the test class recommended booksEditThe publication of the Chinese version of Maven introduced a comparison of the book is "maven combat" Win7 configurationEditThe first thing to install is Jdk1.6 and Myeclipse7.5. 1. MAVEN has an important document "Settings.xml", this file from apache-maven-2.0.8/conf/, to be placed under window, Win7 and WinXP still a little different, Win7---C:\Users\ User name \.m2, WINXP---C:\Documents and settings\ user name \.m2. 2. Set up the MAVEN environment variable, basically similar to setting the JDK environment variable, first set maven_home, then add path. 3. Modify the "settings.xml" file to find the <localRepository>d:/work</localRepository> in this file and make changes. This line represents the location of MAVEN's jar-Package warehouse. Work is decentralized with the jar packages that the project uses, and each project can share one work. 4. Myeclipse7.5 and above itself comes with the Maven plugin. If you need to install a plugin using a lower version of MyEclipse, select software Updates from the Help menu, select Find and install, select Search for new features to install-select New remote Site Write Name:maven url:http://M2eclipse.codehaus. org/update/to download the relevant jar packages and plugins. 5. In MyEclipse windows-perferences, in the location, see if the path to the users settings is correct. 6. Build maven Project,file--new-other-java maven Project. 7. Then open project Pom.xml file,
123456789101112131415161718 <projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>maventest</groupId><artifactId>maventest</artifactId><packaging>jar</packaging><version>0.0.1-SNAPSHOT</version><name>MavenQuickStartArchetype</name><url>http://maven.apache.org</url><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies></project>
Add the name of the jar that Maven relies on in this XML file, which is the Add <dependency></dependency> node. For example: Add struts jar packages that you commonly use
12345 < dependency > Code class= "XML Plain" >< groupid > org.apache.struts</ groupid > < artifactid > struts2-core</ artifactid > < version >2.0.11</ version > < / dependency >
8. By the time of posting, the environment has been settled. The next step is to apply MAVEN to package project for everyone. command in CMD: A. MVN Eclipse:clean Clear the previous compilation in Project, re-come to B. MVN Eclipse:eclipse starts compiling MAVEN's project in MyEclipse: A. Select Maven Project Right-click in the Run as to select Maven Cleanb. In MyEclipse, Project-clean starts compiling C. Selecting Maven Project Right-clicking in run as selects Maven install to finish these steps, and if nothing happens, it will generate a target folder in Project, which is what Maven has packaged and released. Life cycleEditThe life cycle of MAVEN is to abstract all the building processes and facilitate unification. Clean (cleanup) cleanup (cleanup all) This life cycle is designed to clean up the project, which consists mainly of the following phases: pre-clean -the work required to perform the project cleanup. clean -cleans up the files generated by the last build project. post-clean -perform the work required to complete the project cleanup. Default validate -verifies that the project is correct and that all necessary information is available. initialize -initializes the build work, such as setting parameters, creating directories, and so on. generate-sources -generates source code for code that is included in the compilation scope. process-sources -handles source code, such as filtering values. generate-resources - process-resources -copy and process the resource files to the target directory, ready to package. compile -Compile the source code in the project. process-classes -to compile the generated files for later work, such as Java class bytecode enhancement. generate-test-sources - Generate test source code for compiled content. process-test-sources -processing the test source code. generate-test-resources -process-test-resources -copy and process the resource file to the target test directory. Test-compile -will need to test the source code to compile to the path. In general, it is the test classpath directory that compiles the Java files in the/src/test/java directory to the target output. process-test-classes -test -run the tests using the appropriate unit test framework. These test codes are not packaged or deployed. Prepare-package -package -accepts compiled code and packages it into a ready-to-publish format, such as a JAR. pre-integration-test -integration-test -deploy the release package to the running environment on demand. post-integration-test -verify -install -Installing the package to the local repository, to other local referencesProvide dependencies. Deploy -completes the integration and publishing work and copies the final package to the remote repository for sharing with other developers. Site Pre-site -performs some preparation before building the project site. site -build the documentation for the project site. Post-site -performs the work required to complete site builds, such as the preparation of site deployment. site-deploy -build the file to the Web server deployment site that you developed. [2] maven Life cycle Reference: Apache maven project[2]  , book "Maven in Action"

Maven Introduction and simple use

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.