The main solution to Maven versus ant is the dependencies between project modules. Making dependent changes easier.
1. Download maven
Add Maven's Bin directory in 2.path
3. Installing MVN
MVN Eclipse:eclipse
4. Writing MAVEN Tests
Common Commands and folder relationships:
MVN Archetype:generate---Directly Generate folder structure
Example code: 01 Structure diagram
The default structure for MAVEN is Src/main/java
02 Structure diagram
The local repository used here is configured in Settings.xml under the Conf folder of the MAVEN installation directory. As follows:
(Only add the
<localRepository>D:/sid/workspace_maven/01/repo</localRepository>
)
Specific as follows:
<?xml version= "1.0" encoding= "UTF-8"?> <!--Licensed to the Apache software Foundation (ASF) under one or more C Ontributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); You are not a use of this file except in compliance with the License. Obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 unless required by applicable or agreed to writing, software distributed under the License are distributed on a "as is" BASIS, without warranties OR CONDITIONS of any KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License. -<!--| The configuration file for Maven.
It can specified at levels: | | 1. User level. This settings.xml file provides configuration for a single user, | and is normally provided in ${user.home}/.m2/settings.xml.
| |
Note:this location can is overridden with the CLI option: | |
-s/path/to/user/settings.xml | | 2. Global level. This settings.xml file provides configuration for all Maven | Users on a machine (assuming they ' re all using the same Maven | installation). It ' s normally provided in |
${maven.home}/conf/settings.xml.
| |
Note:this location can is overridden with the CLI option: | |
-gs/path/to/global/settings.xml | | The sections in this sample file is intended to give you a running start at | Getting the most out of your Maven installation. Where appropriate, the default |
VALUES (values used when the setting isn't specified) are provided.
| |--> <settings xmlns= "http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema
-instance " xsi:schemalocation= "http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" > & lt;! --Localrepository |
The path to the local repository maven would use to store artifacts.
| | Default: ~/.m2/repository <localRepository>/path/to/local/repo</localRepository>-< localrepository>d:/sid/workspace_maven/01/repo</localrepository> <!--Interactivemode | This would determine whether Maven prompts when it needs input. If set to False, | Maven would use a sensible default value, perhaps based on some other setting, for |
The parameter in question.
| | Default:true <interactiveMode>true</interactiveMode> <!--offline |
Determines whether MAVEN should attempt to connect to the network when executing a build. |
This is a effect on artifact downloads, artifact deployment, and others.
| | Default:false <offline>false</offline>--> <!--plugingroups |
This was a list of additional group identifiers that would be searched when resolving plugins by their prefix, i.e. | When invoking a command line like "Mvn prefix:goal". Maven would automatically add the group identifiers |
"Org.apache.maven.plugins" and "Org.codehaus.mojo" if these is not already contained in the list. |--> <pluginGroups> <!--plugingroup |
Specifies a further group identifier to use for plugin lookup. <pluginGroup>com.your.plugins</pluginGroup> </pluginGroups> <!--proxies |
This is a list of proxies which can being used on the the network. | Unless otherwise specified (by system property or command-line switch), the first proxy |
Specification in this list marked as active would be used. |--> <proxies> <!--proxy |
Specification for one proxy, to is used in connecting to the network.
|
<proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>proxyuser</username> <password>proxypass</password>
The project building here is 02 based on the 01 code.
01 Pom.xml in the project
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:s chemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <!--1.mvn Compile 2. Configure the Local warehouse location: Maven/conf/settings.xml 3. Write the Pom 4. Create a program folder 5. Create the Test Folder 6. Fill in the dependency tag 7. Run Test: MVN Test 8. Run clear: MV N Clean 9. Pack after running the Purge: MVN clean package 10. After you run the cleanup, you are packaged and copied to the local warehouse: MVN-<modelversion>4.0.0</mo Delversion> <groupId>cn.edu.zttc.maven.hello</groupId> <!--modules in the project; preferably a project name plus an underscore plus a module name--<ar Tifactid>hello-first</artifactid> <!--fast-build version--<version>0.0.1-SNAPSHOT</version> <!- -<packaging>war</packaging> <name>webapp</name> <dependencies> <DEP endency> <groupId>junit</groupId> <artifactId>junit</artifactId> <VERSION>4.10&L T;/version> <scope>test</scope> </dependency> </dependencies> </project>
02 of Pom.xml
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:s chemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <!--1.mvn Compile 2. Configure the Local warehouse location: Maven/conf/settings.xml 3. Write the Pom 4. Create a program folder 5. Create the Test Folder 6. Fill in the dependency tag 7. Run Test: MVN Test 8. Run clear: MV N Clean 9. Pack after running the Purge: MVN clean package 10. After you run the cleanup, you are packaged and copied to the local warehouse: MVN-<modelversion>4.0.0</mo Delversion> <groupId>cn.edu.zttc.maven.hello</groupId> <!--modules in the project; preferably a project name plus an underscore plus a module name--<ar Tifactid>hello-second</artifactid> <!--fast-build version--<version>0.0.1-SNAPSHOT</version> <! --<packaging>war</packaging> <name>webapp</name>-<dependencies> <de pendency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10& Lt;/version> <scope>test</scope> </dependency> <!--Introducing 01 dependency Classes--<dependency> <groupid>cn.edu.zttc.maven.hell
O</groupid> <artifactId>hello-first</artifactId> <version>0.0.1-SNAPSHOT</version> <scope>compile</scope> </dependency> </dependencies> </project>
The code in 01:
Package Cn.edu.zttc.hello;
public class Hello
{public
String SayHello (String name) {
return "Hello:" +name;
}
public static void Main (string[] args) {
System.out.println ("Hello World");
}
}
Package Cn.edu.zttc.hello;
Import org.junit.*;
Import static junit.framework.assert.*;
public class Testhello
{
@Test public
void Testhello () {
Hello h = new Hello ();
Assertequals (H.sayhello ("Zs"), "Hello:zs");
}
}
The code in 02:
Package Cn.zttc.maven.world;
Import cn.edu.zttc.hello.*;
public class World
{public
static void Main (string[] args) {
Hello h = new Hello ();
H.sayhello ("John Doe");
}
}