Create a maven project, non-manual eclipse

Here eliminating widow maven install, the default installation is successful
maven project directory structure
Here Insert Picture Description
first create a project maven01
Here Insert Picture Description
then maven01 which is src
Here Insert Picture Description
and src which is
Here Insert Picture Description
then main directory is java
the Test directory is java
Here Insert Picture Description
Here Insert Picture Description
and then write the code
package com.imooc. maven.mode1;

public class HelloWorld(){
public String sayHello(){

     return  "Hello World";
 
 }

}

This saved
Here Insert Picture Description
and then write a test class

package com.imooc.maven01.model;

import org.junit.;
import org.junit.Assert.
;

public class HelloWorldTest{

  @Test
  public  void testHello(){
     Assert.assertEquals("Hello World",new HelloWorld().sayHello());
  
  
  }

}

Save here
Here Insert Picture Description
and then we need a pom file to manage
my own from previous projects to get over a
Here Insert Picture Description

This is a basic framework pom

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

! [Insert Picture description here] (https://img-blog.csdnimg.cn/20190608175609113.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzMDc3ODU3,size_16,color_FFFFFF,t_70)

after modification

<?xml version="1.0" encoding="UTF-8"?>


4.0.0
com.imooc.maven01
maven01-model
0.0.1-SNAPSHOT

<dependencies>
<dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version> 4.10</version>
</dependency>
</dependencies>

Here Insert Picture Description
Then there is the root directory

Here Insert Picture Description
Then we open the command line
into the root directory
Here Insert Picture Description
and then compile the project
Here Insert Picture Description
error, syntax error Here Insert Picture Description
recompile errors continue
Here Insert Picture Description
the original class was wrong
Here Insert Picture Description
to remove the brackets
recompile
compiled successfully

Here Insert Picture Description
Then the project, the more this
Here Insert Picture Description
file to compile
Here Insert Picture Description
and run our test case
mvn test
to continue to get an error saying can not find
my next re-clean

Here Insert Picture Description
Here Insert Picture Description
Without compiled

Guess you like

Origin blog.csdn.net/qq_43077857/article/details/91349133