Build a simple Java project using Maven
1. Enter the command line and execute the following statement.
MVN archetype: generate-dgroupid = cn. luxh. app-dartifactid = My-app-darchetypeartifactid = Maven-Archetype-Quickstart-dinteractivemode = false
After the execution is complete, you can see the following results:
Build success. A Java project named my-app is built under the previous user directory (namely c: \ Documents ents and Settings \ administrator.
2. Go to the my-app directory and you will see a pom. xml file, which is the core of Maven.
1) pom indicates the project object model.
2) Pom. xml contains the project construction information, including the project information and project dependencies.
3) the Pom. xml file can be inherited. In large projects, the Pom. XML of sub-modules generally inherits from the Pom. xml of the parent module.
4) the just-built Pom. XML Description
< Project Xmlns = "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/maven-v4_0_0.xsd" > < Modelversion > 4.0.0 </ Modelversion > < Groupid > CN. luxh. app </ Groupid > < Artifactid > My-app </ Artifactid > < Packaging > Jar </ Packaging > < Version > 1.0-Snapshot </ Version > < Name > My-app </ Name > < URL > Http://maven.apache.org </ URL > < Dependencies > < Dependency > < Groupid > JUnit </ Groupid > < Artifactid > JUnit </ Artifactid > < Version > 3.8.1 </ Version > < Scope > Test </ Scope > </ Dependency > </ Dependencies > </ Project >
Node element description:
< Project > Top-level node of the POM File < Modelversion > Object Model Version. For maven2 and maven3, it can only be 4.0.0 < Groupid > The identifier of the Project Creation organization, which is generally the inverted Domain Name < Artifactid > Defines the unique identifier of a project under the identifier of the organization to which it belongs. An organization can have multiple projects. < Packaging > Packaging methods: jar, war, and ear < Version > The version of the current project, snapshot, indicates the snapshot version. < Name > Project name < URL > Project address < Dependencies > Build the jar of Project dependency < Description > Project Description
A project coordinate is uniquely identified by groupid, artifactid, and version.
3. The my-app project structure is as follows:
1) Compile the sourceProgram, Go to the command line, switch to the my-app directory, and execute the command: MVN clean compile
After compilation is successful, a target directory is added to the my-app directory, and the compiled class file is stored in target \ Classes.
2) test, go to the command line, switch to the my-app directory, and execute the command: MVC clean test
The test is successful. There is a test-classes directory under the my-app \ target directory, which stores the testCodeClass file.
3) package, go to the command line, switch to the my-app directory, run the command: MVC clean package, and run the compilation and testing commands before executing the packaging command.
After the build is successful, the my-app-1.0-SNAPSHOT.jar package is generated in the target directory.
4) install the SDK, go to the command line, switch to the my-app directory, and run the command MVC clean install. Before executing the installation command, the system will first execute the compilation, testing, and Packaging Commands.
After the build is successful, the jar package of the Project is installed in the local repository.
5) run the jar package, enter the command line, switch to the my-app directory, execute the command: Java-CP target \ my-app-1.0-SNAPSHOT.jar CN. luxh. App. app