"Go-Organize" in Eclipse, MAVEN project creation

Source: Internet
Author: User

1. Introduction

This article describes how to use the MAVEN plug-in for Eclipse to create a simple MAVEN project and run the MAVEN command in Eclipse.

2. Steps

1) Open the New Project dialog box and select Maven Project (File->new->object->maven->maven project)



2) It's not good to choose Simple Project, so you can choose archetype



3) Select the Archetype named QuickStart and click Next

Archetype: Project skeleton, project directory and file structure



4) Enter Group Id,artifact ID information, version default is 0.0.1-snapshot,package automatically generated based on group ID and Artifact ID

Group Id: Project group to which the project belongs

Artifact ID: ID of the project in the project group

Version: The revision number of the project, the suffix snashot is the meaning of the snapshot, indicating that the version is unstable



5) because a App.java and a Apptest.java file are generated by default when a project is created through QuickStart, we can run the MAVEN command directly

Select Item->run as->maven Test


Operation Result:

Java code
  1. [INFO] Scanning for projects ...
  2. [INFO]
  3. [INFO]------------------------------------------------------------------------
  4. [INFO] Building firstmvn 0.0. 1-snapshot
  5. [INFO]------------------------------------------------------------------------
  6. [INFO]
  7. [INFO]---maven-resources-plugin:2.5:resources (default-resources) @ firstmvn---
  8. [Debug] Execute contextualize
  9. [INFO]  Using ' UTF-8 ' encoding to copy filtered resources.
  10. [INFO] <span style="color: #ff0000;" >skip Non existing resourcedirectory f:\workspace\firstmvn\src\main\resources</span>
  11. [INFO]
  12. [INFO]---maven-compiler-plugin:2.3. 2:compile (default-compile) @ firstmvn---
  13. [INFO] <span style="color: #ff0000;" >nothing to Compile-all classes is up to date</span>
  14. [INFO]
  15. [INFO]---maven-resources-plugin:2.5:testresources (default-testresources) @ firstmvn---
  16. [Debug] Execute contextualize
  17. [INFO]  Using ' UTF-8 ' encoding to copy filtered resources.
  18. [Info]<span style="color: #ff0000;" > Skip Non existing resourcedirectory f:\workspace\firstmvn\src\test\resources</span>
  19. [INFO]
  20. [INFO]---maven-compiler-plugin:2.3. 2:testcompile (default-testcompile) @ firstmvn---
  21. [Info]<span style="color: #ff0000;" > Nothing to Compile-all classes is up to date</span>
  22. [INFO]
  23. [INFO]---maven-surefire-plugin:2.10:test (default-test) @ firstmvn---
  24. [INFO] Surefire Report Directory:f:\workspace\firstmvn\target\surefire-reports
  25. -------------------------------------------------------
  26. T E s T s
  27. -------------------------------------------------------
  28. Running Com.siyuan.firstmvn.AppTest
  29. Tests run: 1, failures: 0, Errors: 0, skipped: 0, time elapsed: 0.012 sec
  30. Results:
  31. Tests run: 1, failures: 0, Errors: 0, skipped: 0
  32. [INFO]------------------------------------------------------------------------
  33. [INFO] BUILD SUCCESS
  34. [INFO]------------------------------------------------------------------------
  35. [INFO] Total time: 1.762s
  36. [INFO] Finished at:tue Sep: si- CST
  37. [INFO] Final memory:4m/72m
  38. [INFO]------------------------------------------------------------------------

Note: The first time you run Maven there may be more additional maven plugin download information

3. Introduction to the project structure



Firstmvn

|--src

|--main

|--java

|--resources

|--test

|--java

|--resources

|--target

|-pom.xml

SRC: Source file directory

TARGET: Compile Directory

The Pom.xml:Project object model, which defines the project's basic information, describes how the project is built, declares dependencies, and so on.

XML code
  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.siyuan</groupId>
  5. <artifactid>firstmvn</artifactid>
  6. <version>0.0.1-snapshot</version>
  7. <packaging>jar</packaging>
  8. <name>firstmvn</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>

Important elements:

Groupid,artifactid,version,packaging

These four elements make up MAVEN's coordinates, which are quite the ID of the project in the Maven world.

Where packaging defaults to jar, can be jar,pom,war and so on.

Dependencies

Project dependencies, consisting of 1 to n dependency, each containing a coordinate and a range of dependencies scope

where scope defaults to compile, indicating that the dependency is valid for both the main code and the test code.

Test indicates that the dependency is only valid for the test, that is, the contents of the Junit-3.8.1.jar can be used in the test code, and the main code cannot be used.

The rest of the scope will be described later.

"Go-Organize" in Eclipse, MAVEN project creation

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.