Here are the tools used myeclipse, so here is talking about the use maven on myeclipse.
1. What is a warehouse?
It used to store dependencies, configuration files, other plug-ins.
When items are added dependent on, the default read dependencies from the local warehouse, local warehouse if no relevant dependence,
maven downloads from a distance warehouse and placed to local warehouse.
2. What is maven coordinates?
maven coordinates for uniquely identifying dependencies or project.
Commonly used maven coordinates: groupId, artifactId, version.
Other maven coordinates, such as: scope, classifier
<?xml version="1.0" encoding="UTF-8"?> <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"> <!--所有的Maven项目都必须配置这四个配置项--> <modelVersion>4.0.0</modelVersion> <!--groupId指的是项目名的项目组,默认就是包名--> <groupId>cn.gacl.maven.hello</groupId> <!--artifactId指的是项目中的某一个模块,默认命名方式是"项目名-模块名"--> <artifactId>hello-first</artifactId> <!--version指的是版本,这里使用的是Maven的快照版本--> <version>SNAPSHOT-0.0.1</version> </project>
3.怎么知道maven坐标?
网址: https://mvnrepository.com/artifact/junit/junit/4.13-beta-3 ,如图
4. 怎样使用 myeclipse 创建 maven 项目?
首先,在空白处 ,右键,new ---> other
然后,选择 Maven Project ---> Next
勾选 创建简单项目----> Next
填写坐标,如图:
生成的,默认项目目录及文件说明,如图:
5. 添加依赖运行测试
a. 修改 pom.xml , 添加 junit 依赖
b. 编写测试类
在如下位置,添加 HelloWorld.java 类
Helloworld.java
package mvn_helloworld; import org.junit.Test; public class HelloWorld { @Test public void hello(){ System.out.println("hello world"); } }
c. 运行测试类,效果如下