Create a new MAVEN project in Eclipse

Source: Internet
Author: User
Tags object model testng

Good information about Maven:

Apache Official website: http://maven.apache.org/

Apache Maven Primer (top): http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-1-406235-zhs.html

Apache Maven Introductory article (bottom): http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-2-405568-zhs.html

Maven Tutorial: http://www.yiibai.com/maven/maven_environment_setup.html

Konghao maven Video Tutorial: HTTP://WWW.ICOOLXUE.COM/ALBUM/SHOW/45


1. Right-click in Eclipse, New->maven project, Next, and enter project information:

Group Id:com.maven.demo

Artifact Id:mavendemo

Version: Just choose "0.0.1-snapshot".

Package: This column is automatically populated with the form of the Group id.artifact Id. No tube.

After clicking Finish, the project is new and completed. Where the "Src/main/java" directory contains the project's source code, the "Src/test/java" directory contains the test code for the project, and Pom.xml is the project object model for the project.

Directory File
/ Store Pom.xml and all subdirectories
/src/main/java Source code of the project
/src/main/resource Resources to be used by the project
/src/test/java Test source code for the project
/src/test/resource Test the resources you need to use
/target Compile the resulting file

2.Maven uses a concept called Project object Model (POM) to manage projects, and all project configuration information is defined in a file called Pom.xml. With this file, MAVEN can manage the entire lifecycle of a project, including compiling, building, testing, publishing, reporting, and more. We open the Pom.xml file and see the contents as follows:

[HTML]View Plaincopy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "
  2. xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
  3. <modelversion>4.0.0</modelversion>
  4. <groupId>com.maven.demo</groupId>
  5. <artifactid>mavendemo</artifactid>
  6. <version>0.0.1-snapshot</version>
  7. <packaging>jar</packaging>
  8. <name>mavendemo</name>
  9. <URL>http://maven.apache.org</url>
  10. <properties>
  11. <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
  12. </Properties>
  13. <dependencies>
  14. <dependency>
  15. <groupId>junit</groupId>
  16. <artifactid>junit</artifactid>
  17. <version>3.8.1</version>
  18. <scope>test</scope>
  19. </Dependency>
  20. </Dependencies>
  21. </Project>

<project;: The top-level element in all pom.xml files, declaring some pom-related namespaces and XSD elements to constrain Maven's notation.

<modelversion: Refers to the version of the object model used by POM. This value is rarely changed, for Maven2 and Maven3, only 4.0.0.

<groupId: This value is derived from the "Group Id" that we entered when we created the project. Indicates the unique identification of the organization or group that created the project. GroupID is the key identification of the project, which is defined in the fully qualified name of the organization. For example, Org.apache.maven.plugins is the GroupID specified by all Maven plugin projects.

<Artifactid: This value is derived from the "Artifact Id" that we entered when we created the project. Indicates the base name of the main product produced by this project. The main product of a project is usually a jar file. Second, the source code package typically uses Artifactid as part of the last name. The typical product name uses this format: <artifactid>-<version>. <extension> (for example: Myapp-1.0.jar).

<version: This value is derived from the "version" that we selected when we created the project. Represents the version number of the project product. MAVEN helps you manage versions, and you can often see this version of snapshot, meaning snapshots, which indicate that the project is in the development phase and is an unstable version.

<packaging: Refers to the format of the main product produced by the project.

In Pom, groupid,artifactid,packaging,version is called the coordinates of MAVEN, it can only determine a project. With Maven's coordinates, we can also be used to specify other projects, plugins, or parent projects on which our projects depend. The general MAVEN coordinates are written in the following format:

GroupId:artifactId:packaging:version

Examples like ours can be written as:

Com.mycompany.helloworld:helloworld:jar:1.0-snapshot

Our Maven example is simple, but a large project is typically divided into several sub-projects. In this case, each subproject will have its own POM file, and then they will have a common parent project. This makes it possible to build all of the child projects as long as the parent project is built. The Pom of the subproject inherits the parent project's POM. In addition, all POM has inherited a super-pom. Super-pom sets some default values, such as the default directory structure, the default plug-in, and so on, which follows the Convention's better-than-configured principle. So although our POM is simple, it's just a visible part of it. The POM at run time is much more complex. If you want to see the full contents of the POM at run time, you can run the following command:

$MVN Help:effective-pom

<: The display name of the project, typically used in a MAVEN-generated document. The value defaults to Artifactid.

<URL: Specifies the project site, typically used in a MAVEN-generated document.

<properties: The "Properties" of the project. Corresponds to "Properties" right-click on the project. You can configure the encoding method used in the project and so on.

<dependencies: Refers to the dependency of the project. Usually consists of a lot of <dependency>, where the default is only "junit-3.8.1".

<dependency;: a dependent unit. This means that the project needs to rely on a "groupid and Artifactid for JUnit, and version is 3.8.1" Another project, in fact, is the "Junit-3.8.1.jar" package. In practice, if we need a jar package, we will add a <dependency> unit and then MAVEN will automatically help us download the jar package we need after updating the project.

Below we will download the package required for the project by changing the Pom.xml method.

Change Pom.xml, add junit4.8 and testng dependencies, i.e.:

[HTML]View Plaincopy
  1. <dependency>
  2. <groupId>org.testng</groupId>
  3. <artifactid>testng</artifactid>
  4. <version>6.1.1</version>
  5. <scope>test</scope>
  6. </Dependency>
  7. <dependency>
  8. <groupId>junit</groupId>
  9. <artifactid>junit</artifactid>
  10. <version>4.8.2</version>
  11. </Dependency>

3. Update the project. Right-click on the project and select Maven-> "Update project". More updates, you can see the project structure of a "Maven Dependencies" library. Open the library to see our newly added junit and testng packages.

Create a new MAVEN project in Eclipse

Related Article

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.