Reproduced MAVEN Beginner's introductory notes

Source: Internet
Author: User

Recently in a study of Maven, wrote a simple study note.

All information in this article Baidu Cloud address: Http://pan.baidu.com/s/1jGn27PG

First, you need to build a nexus on this machine.

The first step is to place the Nexus-2.1.2.war in the Maven summary data \ Tools directory directly under the D:\Tomcat 7.0\webapps directory.

In the second step, after Tomcat is started, a nexus-2.1.2 directory is generated in the WebApps directory.

Step three, stop Tomcat, modify the nexus-2.1.2 directory name to Nexus. Start Tomcat again, Access Http://127.0.0.1:9999/nexus Normal, indicating the successful installation of the Nexus, the native computer IP is 10.1.16.158,tomcat port 9999

The following directories:

Objective

1.Maven Local Installation

2. Configuring Maven in Eclipse

3. Build a Web project in eclipse

4. Using MAVEN to manage the web in eclipse

Objective

My computer uses the operating system for XP, the following documents are based on my computer environment to explain and configure.

1.Maven Local Installation

1. Check the JDK installation (more than 1.6 versions):

Echo%java_home%

Java-version

After entering the command line window, if the feedback in the interface appears, it indicates that the native JDK is not installed, the environment variable is not set or the configuration is problematic. You will need to install the JDK and configure the environment variables, here is no longer how to install, the default native has installed the JDK and configured in the PATH environment variable.

2. Set the system environment variable, java_home

You can see that my JDK directory location is D:\JDK

3. Unzip the Apache-maven-3.0.5-bin.zip in the tool directory, for example, unzip to the following directory (unzip the directory without the Chinese text, no spaces):

D:\apache-maven-3.0.5, the directory structure after decompression, such as.

4. Set the system environment variable, maven_home

5. Set the environment variable path, add%maven_home%\bin to path, be sure to use semicolons; separate from other values

6. Verify the installation is successful, open the Cmd window, and click Mvn-v to view

appears as on the page stating that MVN has been installed successfully.

2. Configuring Maven in Eclipse

1. Copy the D:\apache-maven-3.0.5\conf\settings.xml file to the directory C:\Documents and SETTINGS\USER\.M2. If the user is different from the computer, you need to change the user to the current computer login name. If there is no. m2 directory, this directory is automatically generated when the MVN clean command is executed in the cmd window, as

The error message is because there is no Pom.xml file in the current directory, you can temporarily leave the tube.

2. The Java version of Eclipse in the Unzip tool directory plus the SVN plugin installed. rar to D disk, the D-disk version of the Java EE Plus installed SVN plug-in directory under the Eclipse directory cut to the D-packing directory, after opening the Eclipse directory.

3. Click Eclipse.exe to open Eclipse and configure the MAVEN environment in Eclipse. The default working space for Eclipse is D:\eclipse\workspace. After clicking Preferences under Window in Eclipse, click on installations under Maven in the Action window that pops up.

In the option installations, click Add to select the native Maven install root directory, such as.

Click OK, like.

This has added local maven to eclipse, because the eclipse and MyEclipse self-contained maven is very unstable, and you need to configure MAVEN to use native installation in the development tools.

Configure the user settings option below and click User Settings.

For example, if the settings.xml is modified, you need to click Update Settings. The default Maven local warehouse location can be seen in C:\Documents and settings\user\.m2\repository

Here, the MAVEN environment in Eclipse is configured so that you can build your project in Eclipse and use Maven.

3. Build a Web project in eclipse

The first step, click File-new-project in Eclipse, select Maven Project, such as.

Second step, click Next, like.

Third step, directly click on next, such as.

Fourth step, in the need to select Maven-archetype-webapp, click Next after, such as.

Fifth step, fill in the data, where projectname can be modified to the abbreviated name of the project, Mavenweb as the project name, version selection by default (default to the snapshot version), click Finish, a Mave Web project is established, Switch to Java view and build the project directory structure as.

As you can see in the MAVEN Web project created by eclipse yourself, you need to manually create some catalogs to fully meet the MAVEN conventions. Instead of manually creating the directory here, we manually import a MAVEN project that has already created an additional directory based on the MAVEN conventions.

4. Using MAVEN to manage Web projects in eclipse

The first step is to copy the Maven summary data \ Nexusmaven under the source code directory to the D:\eclipse\workspace directory. After clicking File-import in Eclipse, like.

The second step, choose Maven under existing Maven Projects, click Next, like.

The third step, click Browse, select the Nexusmaven directory, such as.

Fourth step, click OK after, such as.

Fifth step, click Next after, like.

Sixth step, click Finish to complete the import project Nexusmaven into Eclipse. Such as.

You can see that Nexusmaven has more than two Src/test/java and Src/main/java directories for MAVEN Web projects that are automatically created by Eclipse.

L Src/main/java Store Project source code

L Src/test/java Store test source code

L src/main/resources Store project configuration file

L The jar under Maven dependencies is the jar for project dependencies

L WebApp Webroot Directory relative to the Web project in MyEclipse

L Target is the project compile, test, document output directory.

Seventh step, modify the Pom.xml under the Nexusmaven project, and change the 127.0.0.1:9999 all to the IP and port number of the MAVEN server, currently 10.1.16.158:9999

Eighth, overwrite the settings.xml file under C:\Documents and settings\user\.m2 with the settings.xml file under the Maven summary Profile \ config file directory, and all 127.0.0.1 in the file : 9999 modified to the IP and port number where the MAVEN server is located, currently 10.1.16.158:9999. The local warehouse is configured in the D:\apache-maven-3.0.5\repository directory in this settings.xml file.

Nineth step, you need to update the settings.xml file by clicking Update Settings in Eclipse.

Tenth step, we will perform the MAVEN operation below.

The project cleanup operation is performed first, and this operation deletes the target build directory, such as.

Select Pom.xml in the Nexusmaven project, right-click, and select Maven clean under Run as. After execution, the console appears with the [INFO] BUILD success Message stating that the cleanup was successful.

[WARNING]

[WARNING] Some problems were encountered while building the effective settings

[WARNING] unrecognised tag: ' Mirror ' (Position:start_tag seen ... e preferred \ n | server for that repository.\n |-->\n\n & Lt;mirror> @163:12) @ C:\Documents and Settings\user\.m2\settings.xml, line 163, column 12

[WARNING]

[INFO] Scanning for projects ...

[INFO]

[INFO]------------------------------------------------------------------------

[INFO] Building Nexusmaven Maven Webapp 0.0.1-release

[INFO]------------------------------------------------------------------------

[INFO]

[INFO]---maven-clean-plugin:2.4.1:clean (default-clean) @ Nexusmaven---

[INFO] Deleting D:\eclipse\workspace\nexusMaven\target

[INFO]------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO]------------------------------------------------------------------------

[INFO] Total time:0.344s

[INFO] Finished at:wed APR 13:08:56 CST 2014

[INFO] Final memory:2m/15m

[INFO]------------------------------------------------------------------------

The following deployment command executes the project into a war package and installs the package to a local warehouse and a server, providing download and dependency services. Select Pom.xml in the Nexusmaven project, right-click, and select Maven build under Run as. After, such as.

Enter deploy in goals and click Run at the bottom to execute the deployment command. After execution, the console appears with the [INFO] BUILD success message stating that the deployment was successful.

[WARNING]

[WARNING] Some problems were encountered while building the effective settings

[WARNING] unrecognised tag: ' Mirror ' (Position:start_tag seen ... e preferred \ n | server for that repository.\n |-->\n\n & Lt;mirror> @163:12) @ C:\Documents and Settings\user\.m2\settings.xml, line 163, column 12

[WARNING]

[INFO] Scanning for projects ...

[INFO]

[INFO]------------------------------------------------------------------------

[INFO] Building Nexusmaven Maven Webapp 0.0.1-release

[INFO]------------------------------------------------------------------------

[INFO]

[INFO]---maven-resources-plugin:2.5:resources (default-resources) @ Nexusmaven---

[Debug] Execute contextualize

[WARNING] Using platform Encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

[INFO] Copying 0 Resource

[INFO]

[INFO]---maven-compiler-plugin:2.3.2:compile (default-compile) @ Nexusmaven---

[WARNING] File encoding have not been set, using platform encoding GBK, i.e. build is platform dependent!

[INFO] Compiling 1 source file to D:\eclipse\workspace\nexusMaven\target\classes

[INFO]

[INFO]---maven-resources-plugin:2.5:testresources (default-testresources) @ Nexusmaven---

[Debug] Execute contextualize

[WARNING] Using platform Encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

[INFO] Skip non existing resourcedirectory D:\eclipse\workspace\nexusMaven\src\test\resources

[INFO]

[INFO]---maven-compiler-plugin:2.3.2:testcompile (default-testcompile) @ Nexusmaven---

[WARNING] File encoding have not been set, using platform encoding GBK, i.e. build is platform dependent!

[INFO] Compiling 1 source file to D:\eclipse\workspace\nexusMaven\target\test-classes

[INFO]

[INFO]---maven-surefire-plugin:2.10:test (default-test) @ Nexusmaven---

[INFO] Surefire Report Directory:d:\eclipse\workspace\nexusmaven\target\surefire-reports

-------------------------------------------------------

T E s T s

-------------------------------------------------------

Running Com.song.wbgy.user.test.UserTest

User [Name=lisong, password=123456]

Tests Run:1, failures:0, errors:0, skipped:0, Time elapsed:0.047 sec

Results:

Tests Run:1, failures:0, errors:0, skipped:0

[INFO]

[INFO]---maven-war-plugin:2.1.1:war (default-war) @ Nexusmaven---

[INFO] Packaging WebApp

[INFO] Assembling WebApp [Nexusmaven] in [D:\eclipse\workspace\nexusMaven\target\nexusMaven-0.0.1-release]

[INFO] Processing War Project

[INFO] Copying webapp resources [D:\eclipse\workspace\nexusMaven\src\main\webapp]

[INFO] Webapp assembled in [msecs]

[INFO] Building War:d:\eclipse\workspace\nexusmaven\target\nexusmaven-0.0.1-release.war

[WARNING] warning:selected war files include a web-inf/web.xml which'll be ignored

(Webxml attribute is missing from the war task, or Ignorewebxml attribute is specified as ' true ')

[INFO]

[INFO]---maven-install-plugin:2.3.1:install (default-install) @ Nexusmaven---

[INFO] Installing D:\eclipse\workspace\nexusMaven\target\nexusMaven-0.0.1-release.war to D:\apache-maven-3.0.5\ Repository\com\song\wbgy\nexusmaven\0.0.1-release\nexusmaven-0.0.1-release.war

[INFO] Installing D:\eclipse\workspace\nexusMaven\pom.xml to D:\apache-maven-3.0.5\repository\com\song\wbgy\nexusMaven\ 0.0.1-release\nexusmaven-0.0.1-release.pom

[INFO]

[INFO]---maven-deploy-plugin:2.7:deploy (default-deploy) @ Nexusmaven---

uploading:http://127.0.0.1:9999/nexus/content/repositories/releases/com/song/wbgy/nexusmaven/0.0.1-release/ Nexusmaven-0.0.1-release.war

uploaded:http://127.0.0.1:9999/nexus/content/repositories/releases/com/song/wbgy/nexusmaven/0.0.1-release/ Nexusmaven-0.0.1-release.war (4 KB at 9.8 kb/sec)

uploading:http://127.0.0.1:9999/nexus/content/repositories/releases/com/song/wbgy/nexusmaven/0.0.1-release/ Nexusmaven-0.0.1-release.pom

uploaded:http://127.0.0.1:9999/nexus/content/repositories/releases/com/song/wbgy/nexusmaven/0.0.1-release/ Nexusmaven-0.0.1-release.pom (2 KB at 8.2 kb/sec)

Downloading:http://127.0.0.1:9999/nexus/content/repositories/releases/com/song/wbgy/nexusmaven/maven-metadata.xml

Uploading:http://127.0.0.1:9999/nexus/content/repositories/releases/com/song/wbgy/nexusmaven/maven-metadata.xml

Uploaded:http://127.0.0.1:9999/nexus/content/repositories/releases/com/song/wbgy/nexusmaven/maven-metadata.xml (319 B at 3.3 kb/sec)

[INFO]------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO]------------------------------------------------------------------------

[INFO] Total Time:3.016s

[INFO] Finished at:wed APR 13:13:08 CST 2014

[INFO] Final memory:10m/25m

[INFO]------------------------------------------------------------------------

The execution of the MAVEN deploy command is detailed in the output information and the result of the execution.

Note:

1. How to build a Web project in Eclipse, see address Http://hi.baidu.com/sdhzlzhk/item/3c0b26c42786517189ad9e80

2. Maven Web Project can also click Run on server to start the server test under Run as, before you need to establish a server project, to create a method, please see HTTP://HI.BAIDU.COM/SDHZLZHK /item/3c0b26c42786517189ad9e80

3, MAVEN project jar to add the way and the past is very different, Maver project uses its own dependency management, through the configuration of Pom.xml to implement the dependency management of the jar package, see the files in the data directory. MAVEN uses warehouses and private private to manage jar packages, a jar package that needs to be added only once, and others can be configured to use Pom.xml, without having to download and add them repeatedly.

4. Maven can compile, test, package, and generate documents for the project to be executed together through MAVEN deploy. MAVEN-generated documents are generally not used.

5. If you want to publish an official version of the project, you need to include the release keyword in the version attribute value in the Pom.xml file so that the project will be published to the official repository of the database, otherwise it will be published as an unofficial version of the snapshot repository.

6, when using the Maven release version, the need for a certain specification and system, you can refer to the following MAVEN version management.

Article is the use of the installation package and documents Baidu Cloud share address: Http://pan.baidu.com/s/1q5wBG

Reproduced MAVEN Beginner's introductory notes

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.