Maven Architecture Build Command line and learning notes (i)

Source: Internet
Author: User

command line and learning notes for Maven architecture

==================================================

1. Configure Environment variables:

Description

Differences between system environment variables and user variables

Why do I sometimes set environment variables when I build a compilation environment, and sometimes we set user variables?


Environment variables are divided into system environment variables and user environment variables.

The environment variable you call refers to the system environment variable, which works for all users

User environment variables only work for the current user.


For example, if you want to use Java, then you add the Java Bin directory under the PATH variable, then it is the system environment variable, all users login, command line input Java will have Java help information come out. And if you create a new variable under a user's variable, it will be useful only to that user, and when you log in as a different user, the variable will not exist.


2. How to query environment environment variables:

C:\users\administrator>echo%m2_home%d:\java\apache-maven-3.2.3c:\users\administrator>mvn-vapache maven 3.2.3 (33F8C3E1027C3DDDE99D3CDEBAD2656A31E8FDF4; 2014-08-12t04:58:10+08:00) Maven home:d:\java\ Apache-maven-3.2.3java version:1.6.0_29, Vendor:sun Microsystems Inc.java Home:d:\java\jdk1.6\jredefault Locale:zh_ CN, platform Encoding:gbkos name: "Windows 7", Version: "6.1", Arch: "x86", Family: "Windows" c:\users\administrator>

----

3.Maven initializes the repository to perform mvn help:system Query environment parameters and download basic maven to the default ~/m2 settings.

The system is automatically from the Central library (if you configure a proxy server, or a Nexus server)

Download the Maven-help-plugin plugin.

Second, get the environment information, finally show the environment variable information, (use ...) Omit relevant information)

s/plexus-utils/1.5.7/plexus-utils-1.5.7.pom  (8 kb at 8.2 kb/sec) Downloading:  Http://localhost:8081/nexus/content/groups/public/jdom/jdom/1.0/jdom-1.0.pomDownloaded: http://localhost :8081/nexus/content/groups/public/jdom/jdom/1.0/jdom-1.0.pom  (2 KB AT 1.8 KB/SEC) ......................................stream/xstream/1.4.3/xstream-1.4.3.jar  (471 KB at  20.2 KB/SEC) [info]======================================================================================= ================= platform properties details ============================================ =============================================================================================================== ============================system properties============================================================ ===================java.runtime.name=java (TM)  se runtime environmentsun.boot.library.path=d:\ Java\jdk1.6\jre\binjava.vm.version=20.4-b02java.vm.vendor=sun microsystems inc.java.vendor.url=http://java.sun.com/ ......... java.endorsed.dirs=d:\java\jdk1.6\jre\lib\endorsedos.arch=x86java.io.tmpdir=c:\users\admini~1\ Appdata\local\templine.separator=java.vm.specification.vendor=sun microsystems inc.user.variant= Os.name=windows 7classworlds.conf=d:\java\apache-maven-3.2.3\bin\m2.confsun.jnu.encoding=gbk ...................... sun.io.unicode.encoding=unicodelittlesun.cpu.endian=littlesun.desktop= Windowssun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386  i86===============================================================================Environment  Variables===============================================================================classworlds_jar= "D:\ Java\apache-maven-3.2.3\boot\plexus-classworlds-2.5.1.jar "Tmp=c:\users\admini~1\appdata\local\tempprogramfiles (X86) =c:\program files  (x86) COMPUTERNAME=PC201408041613os=windows_ntprompt= $P $g ..... ..... ..... .................................... home=c:\users\administratorprocessor_level=6error_code=0sessionname=consoleusername=administratorpathext=.com;. EXE;. BAT;. CMD;. VBS;. VBE;. JS;. JSE;. WSF;. WSH;. mscwindows_tracing_flags=3public=c:\users\publicprocessor_revision=2505[info] --------------------------- ---------------------------------------------[info] build success[info] ----------------------- -------------------------------------------------[info] total time: 03:18 min[info]  finished at: 2014-12-19t13:32:51+08:00[info] final memory: 5m/15m[info] -------- ----------------------------------------------------------------c:\users\administrator>

End of construction



3.1. Maven3.1.1. Maven Introduction
    • We use MAVEN to build the application environment, so let's start by simply introducing Maven. What is maven? How to answer this question depends on how you look at the problem. Most MAVEN users call maven a "build tool": A tool used to construct source code into a published component. Build engineers and project managers will say Maven is a more complex thing: a project management tool. So what's the difference? Building tools like Ant are focused only on preprocessing, compiling, packaging, testing, and distributing, while a project management tool such as MAVEN provides a superset of the functionality provided by the build tool, in addition to providing built-in functionality, Maven can generate reports, build Web sites, and help drive missions Communication between members of the team.

    • The latest version of Maven is 2.1.0. Because the maven2.0 version is completely redesigned compared to maven1.0 and faster than before, so called Maven2. At present, many open-source projects have been built using MAVEN2, which is a good indication of its popularity and ease of use. Note: Maven referred to in this guide refers to Maven2.

3.1.2. Maven Common Commands
  • MVN archetype:create: Creating a Maven Project

  • MVN compile: Compiling source code

  • MVN test-compile: Compiling test code

  • MVN test: Running unit tests in the application

  • MVN site: Sites that generate project-related information

  • MVN clean: Clears the build results from the target directory

  • MVN package: Generate Jar files from project

  • MVN install: Installing the jar in the local Repository

  • MVN eclipse:eclipse: Generate Eclipse Project file

  • Mvn-dmaven.test.skip=true: Ignoring test document compilation

3.2. POM

The full name of the POM is the Project object model, which is the item. Pom.xml is MAVEN's project description file, which resembles the Project.xml file with Antx. The Pom.xml file describes the project's information in XML, including the project name, version, project ID, project dependencies, compilation environment, continuous integration, project team, contribution management, generating reports, and so on. In summary, it contains all the project information.

3.2.1. Basic configuration of Pom.xml
<project xmlns= "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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > & Lt;modelversion>4.0.0</modelversion> <groupId>org.codehaus.mojo</groupId> <artifactid >my-project</artifactId> <version>1.0</version></project>

Modelversion describes which version of the project descriptor the Pom file is to follow.

GroupId a universally unique identifier for a project. Usually the name of a completely correct package is used to distinguish it from other items (for example: Org.apache.maven).

Artifactid The identifier specified for artifact within a given GroupID group is unique, and artifact represents the component (output) that was made or applied by a project.

Version of the artifact produced by the current project of version

The above 4 elements are integral, where groupid, Artifactid, and version describe the project-dependent unique flag.

3.2.2. pom.xml file Structure
<project>  <modelVersion>4.0.0</modelVersion>  <!- The  Basic information about the basics    project->  <groupid>...</groupid>  <artifactid >...</artifactid>  <version>...</version>  <packaging>...</ Packaging>  <dependencies>...</dependencies>  <parent>...</parent >  <dependencyManagement>...</dependencyManagement>  <modules>...< /modules>  <properties>...</properties>  <!- build settings Compilation settings for    project->  <build>...</build>  <reporting>...</ reporting>  <!- more project information  Other project information  ->  < name>...</name>  <description>...</description>  <url>...</ Url>  <inceptionyear>...</inceptionyear>  <licenses>...</licenses>  < organization>...</organization>  <developers>...</developers>  < contributors>...</contributors>  <!-- Environment Settings  ->   <issuemanagement>...</issuemanagement>  <cimanagement>...</ cimanagement>  <mailinglists>...</mailinglists>   <scm>...</ scm>  <prerequisites>...</prerequisites>  <repositories>...</ repositories>  <pluginrepositories>...</pluginrepositories>  < Distributionmanagement>...</distributionmanagement>  <profiles>...</profiles> </project>

Project is the root node of pom.xml and for other elements refer to Pom Reference

3.2.3. Pom is an important 3 relationship

POM has 3 important relationships: dependency, inheritance, composition.

3.2.3.1. Dependencies
<dependencies> <dependency> <groupId>junit</groupId> <artifactid>junit</arti      factid> <version>4.0</version> <type>jar</type> <scope>test</scope> <optional>true</optional> </dependency> ...</dependencies>

If you want to rely on a jar package that is not in a MAVEN library, the simple way to do this is to install the jar package to the local MAVEN library using the following command:

MVN install:install-file-dfile=my.jar-dgroupid=mygroup-dartifactid=myartifactid-dversion=1

Then add the dependency.

3.2.3.2. Inheritance Relationships

Another powerful change that MAVEN brings is Project inheritance.

3.2.3.2.1. Defining a parent Project
<project> <modelVersion>4.0.0</modelVersion> <groupid>com.mygroup </groupId> < Artifactid>my-parent</artifactid> <version>2.0</version> <packaging>pom</packaging ></project>

The packaging type, defined as POM, is used to define multiple items as parent and composite. Of course the Pom of the MAVEN project we created inherits Maven's Super Pom, and if you want to see the full POM structure of the project (parent or child), you can run:

MVN Help:effective-pom

You can do it.

3.2.3.2.2. Sub-project configuration
<project> <modelVersion>4.0.0</modelVersion> <groupid>com.mygroup </groupId> <        artifactid>my-child-project</artifactid> <parent> <groupid>com.mygroup </groupId> <artifactId>my-parent</artifactId> <version>2.0</version> <relativepath> /my-parent</relativepath> </parent></project>

RelativePath may not be needed, but it is used to indicate the parent's directory for quick querying.

3.2.3.3. Synthetic relationships

A project has multiple modules, also called multiple modules, or synthetic projects. The definition is as follows:

<project> <modelVersion>4.0.0</modelVersion> <groupid>com.mygroup </groupId> < artifactid>my-parent</artifactid> <version>2.0</version> <modules> <module>my-c Hild-project1<module> <module>my-child-project2<module> </modules></project>

Where module describes the relative path of the subproject.

3.2.4. Dependencymanagement and Profile

Maven also provides a dependencymanagement element to provide a way to unify dependent version numbers. The dependencymanagement element is typically used on the top-level parent POM. Using the Dependencymanagement element in Pom.xml allows you to reference a dependency in a subproject without explicitly listing the version number. Maven walks up the parent-child hierarchy until a project with the dependencymanagement element is found, and then it uses the version number specified in the Dependencymanagement element, which solves the problem of modifying the incomplete dependent version number.

Maven's profile element can customize a particular build for a particular environment, making portability possible between different environments. For example, to use production profile to run MVN install, you need to pass in the-pproduction parameter at the command line, where production is the profile ID. To verify that the production profile overrides the default compiler plug-in configuration, you can run Maven like this by turning on debug input (-X).



Maven Architecture Build Command line and learning notes (i)

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.