MAVEN Environment Quick Build

Source: Internet
Author: User

Recently, MAVEN was used in development, so it was easy to learn from Maven. Because there is a Maven master in the side, so, soon to get started, I am a self-summary here. Please refer to other articles for more information on what MAVEN is.

----------------Ready to work-------------

JDK 1.6 Java Development environment.

Eclipse IDE One.

Maven 3.1.1

----//Quick Build steps

First step: Configure the MAVEN environment

Unzip the download file and set up the maven environment

If you've configured the JDK, this should be easy for you. As in my maven environment: F:\maven\apache-maven-3.1.1

My Computer ----- Properties ---- Advanced ----- Environment Variables ----- Environment Variables ----- new

Variable name: m2_home

Variable Value: F:\maven\apache-maven-3.1.1

Find Path

Add at the end of the environment variable value:;%m2_home%\bin; Note the semicolon---front

Of course, you can also join directly under path path:; F:\maven\apache-maven-3.1.1\bin is just a little more elegant in the way above.

I'm building a new

Open a command prompt (start --- run ---cmd)to check if our Java environment and maven environment are wrong.

Step two: Modify the warehouse location

Modify our warehouse address to store all the jar packages that our project relies on .

My warehouse path: F:\maven\repo---- This path is created by myself and you can create the path in any location.

We open the Setting.xml file in the \apache-maven-3.1.1\conf\ directory and set it to the warehouse path we created .

Let's verify with a command. Open a command prompt, enter:mvn help:system

This command prints out all of the Java System Properties and environment variables. This information is very helpful to our daily programming work.

If there are no errors during the run, opening our warehouse (F:\maven\repo) will find some more files inside. These files are downloaded from maven 's central repository to the local repository.

Step three: Create a MAVEN project

Create a project of our own.

We create a project with the MAVEN command line method

MVN archetype:create-dgroupid=com.imeixi.test-dartifactid=hello-dpackagename=com.imeixi.test-dversion=1.0

(Execution error: cause analysis: Create is deprecated in Maven 3.0.5 and beyond, discard create in maven3.0.5 version, use generate Build project)

Command modified to:

MVN archetype:generate-dgroupid=com.imeixi.test-dartifactid=hello-dpackagename=com.imeixi.test-dversion=1.0

Because it is the first time the project is built, all the dependent jar packages are downloaded from MAVEN's central repository, so it takes time to wait. After we have accumulated our usual jar packages in our local warehouse, our development will become very normative and convenient. ^_^!!

With the time to download the jar pack, let's take a look at the Pom.xml file.

<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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<Modelversion>4.0.0</Modelversion>

<GroupId>com.chongshi.test</GroupId>
<Artifactid>hello</Artifactid>
<Version>1.0</Version>
<Packaging>jar</Packaging>

<Name>hello</Name>
<Url>http://maven.apache.org</Url>

<Properties>
<Project.build.sourceEncoding>utf-8</Project.build.sourceEncoding>
</Properties>

<Dependencies>
<Dependency>
<GroupId>junit</GroupId>
<Artifactid>junit</Artifactid>
<version< Span style= "color: #0000ff;" >>3.8.1</version >
<scope< Span style= "color: #0000ff;" >>test</scope
</dependency >
</>
</ project>

The top-level element in the Øproject:pom.xml file;
Ømodelversion: Indicates the version of the object model used by the POM. This value is rarely changed.
Øgroupid: Indicates the unique identification of the organization or group that created the project. GroupID is a key identification of the project, typically 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: Indicates the basic name of the main product produced by this project. The main product of a project is usually a jar file. Second, like 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: The version number of the project product. MAVEN helps you manage versions, and you can often see this version of snapshot, indicating that the project is in the development phase.

Øname: The display name of the project, typically used in a MAVEN-generated document.

Øurl: Specifies the project site, typically used in a MAVEN-generated document.

Ødescription: Describes this project, typically used in a MAVEN-generated document.

For a project only the following part is what we need to focus on:

<groupId>com.chongshi.test</groupId>

<artifactId>hello</artifactId>

<version>1.0</version>

Fourth step: Compiling the project code

Our project has been created and completed. But we opened the catalog and found that it was not the project directory format that we needed for eclipse. We need to build it into a project that our eclipse can import.

At the command prompt, go to our created project directory (F:\maven\hello) and execute: mvn cleancompile

Clean tells Maven to clear the input directory Target/,compile to tell Maven to compile the project Master code.

Don't worry, we need another time to download the relevant jar package. ^_^! Use Maven for the first time to learn to be calm.

The project is compiled, but the project's directory structure is not the project structure of eclipse that we want, and it cannot be imported into eclipse. Therefore, you need to execute a command:mvn eclipse:eclipse

After the command is completed, we need the project directory.

Fifth step: Import Eclipse Tools

Open our Eclipse tool.

Configure the Maven warehouse path First

Window----perferences-----java-----Build Path-----Classpath Variables

New class path for a variable.

Name:M2_repo Note this name must be capitalized.

Path:f:/maven/repo click "Folder ..." to find a location with a local warehouse.

Below, you can import my Hello project. How Eclipse imports the project, I won't say it here, if you're a Java developer.

Sixth step: package updates and downloads

Open Project Discovery Our JUnit is 3.8.1, a bit old. So I'd like to switch to 4.7, how to change it through MAVEN. In fact, it's very simple to open the Pom.xml file under our project.

......
<Dependencies>
<Dependency>
<GroupId>junit</GroupId>
<Artifactid>junit</ Artifactid>
< version>4.8.1< /version>
< scope>test</< Span style= "color: #800000;" >scope>
</>
</ dependencies>
...

Change the version number of JUnit and then re-execute: mvn eclipse:eclipse

Maven Central Warehouse address: http://search.maven.org

If we want to download a struts jar package. Search for strruts in the search box to list all struts versions in the central repository .

The format of the list corresponds to the format of our pom.xml configuration file.

We add in the Pom.xml:

<groupId>stuts</groupId>

<artifactId>struts-scripting</artifactId>

<version>1.0.1</version>

Then update the project to download any jar package we want from the central repository (must be an open source package)

Continue to study content:

1. How do I create a Web project?

This is necessary if MAVEN is to be applied to project development.

2. How do I use jeety?

A container provided by MAVEN, similar to Tomcat

3. How do I create an agent repository?

If it is a team development, this is necessary, we can not go to the central warehouse every time to pick up the bag, that is very slow, if developer A has been under a package, Developer B will be next; Create the Agent warehouse, a first time the package will be deposited in the agent warehouse, B to be taken directly from the Agent warehouse row.

Maven Environment Quick Build (GO)

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.