Hello everyone, I am Cola, a dedicated original, willing to share the program ape. This series of tutorials will continue to be updated, you can search “IT Cola” on wechat to read the first time. Ebooks has a huge selection of free books that I’ve selected for you

In this chapter, we’ll look at some common Maven commands. Due to execute the command is the basis of the project, so we need to create a Maven project, specifically how to create, in a blog post on introduced: www.cnblogs.com/ysocean/p/7…

1. Create Maven project

package com.ys.maven; Public class HelloMaven {// Pass in a String and return public String Hello(String name){returnname; }}Copy the code

Create a com.ys.maven package in SRC /test/ Java and create helloTest.java

package com.ys.maven;

import junit.framework.Assert;
import org.junit.Test;

public class HelloTest {
	
	@Test
	public void testHello(){
		HelloMaven he = new HelloMaven();
		String name = he.Hello("Tom"); // Check whether the argument passed in Hello is valid"maven"
		Assert.assertEquals("maven", name); }}Copy the code

Pom. XML file is as follows:

<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/xsd/maven-4.0.0.xsd">
  	 
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ys</groupId>
  <artifactId>hellomaven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <dependencies>
  	<dependency>
  		<groupId>junit</groupId>
  		<artifactId>junit</artifactId>
  		<version>4.0</version>
  		<scope>test</scope>
  	</dependency>
  </dependencies>
</project>
Copy the code

And we’ll talk more about why we did that.

2, Maven common commands

1. Compile Java source programs into class bytecode files. 2, MVNtestTest, and generate test report 3, MVN clean will be compiled before the old class bytecode file delete 4, MVN Pakage package, dynamic Web project war package, Java project jar package. 5, MVN install puts the project generated JAR package in the repository for other modules to callCopy the code

①, compile: Compile Java source programs into class bytecode files.

Step 1: Select the pom. XML file, right-click on it and >Run As —->2 Maven build…

②, test: test, and generate test report

Step 1: Select the pom. XML file, right-click on it and >Run As —->2 Maven build… Then enter test in the popup box or select the pom. XML file, right-click it, and >Run As——>6 Maven test. Step 2: View the console

Analyzing the test program, we pass in the parameter Tom, and we want maven, obviously not equal, then the test fails

③ MVN clean removes the old class bytecode files from the previous compilation

Step 1: Select the pom. XML file, right-click on it and >Run As —->2 Maven build… In the dialog box that pops up, type clean or select the pom. XML file and right-click –>Run As——>3 Maven clean

④, MVN Pakage package, dynamic Web engineering war package, Java engineering JAR package.

Step 1: Select the pom. XML file, right-click on it and >Run As —->2 Maven build… And then enter Package in the pop-up box

This series of tutorials will continue to be updated, you can search “IT Cola” on wechat to read the first time. Reply ebook has a selection of books that I have selected for you