Maven(三)-依赖自己的程序

来源:互联网 发布:红米note3网络制式 编辑:程序博客网 时间:2024/06/05 01:11
之前的一个HelloWorld,使用到了Junit
所以在pom.xml配置了junit的依赖


现在我们要另外写一个工程,依赖于该工程的类.




1.创建文件夹.maven-02


2.老规矩,创建pom.xml,src/test/java


3.新建一个测试类 TestDependency.java



package com.aii.maven;import org.junit.*;import static org.junit.Assert.*;public class TestDependency{@Testpublic void testHello(){String result=new HelloWorld().sayHello("maven");assertEquals(result,"hello:maven");}}


4.修改pom.xml,指定groupId,artifactId,version,对应自己的程序


<?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">    <modelVersion>4.0.0</modelVersion>    <groupId>com.aii.maven.hello</groupId>    <artifactId>hello</artifactId>    <version>1.0-SNAPSHOT</version><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.10</version></dependency><dependency><groupId>com.aii.maven.hello</groupId><artifactId>hello</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies></project>



5.安装自己的程序到maven仓库




6.mvn test测试成功








************


现在在maven-02目录下多了一个文件夹-target

这个文件夹是用来存放一些信息的,比如说测试的日志等等.

使用命令 mvn clean 可以清空该文件夹



0 0