echo %JAVA_HOME%
Maven 默认的本地仓库:~\.m2\repository
目录(~
表示当前用户的家目录)。
Maven 的核心程序并不包含具体功能,仅负责宏观调度。具体功能由插件来完成。Maven 核心程序会到本地仓库中查找插件。如果本地仓库中没有就会从远程中央仓库下载。此时如果不能上网则无法执行 Maven 的具体功能。为了解决这个问题,我们可以将 Maven 的本地仓库指向一个在联网情况下下载好的目录。
<setting ...>
<localRepository>D:\Maven\MavenRepository</localRepository>
<mirrors>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</settting>
<?xml version="1.0" ?>
<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>cn.edu.nuist.maven</groupId>
<artifactId>Hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Hello</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
package cn.edu.nuist.maven;
public class Hello {
public String sayHello(String name){
return "Hello "+name+"!";
}
}
package cn.edu.nuist.maven;
import org.junit.Test;
import static junit.framework.Assert.*;
public class TestHello {
@Test
public void testHello(){
Hello hello = new Hello();
String results = hello.sayHello("baishizhu");
assertEquals("Hello baishizhu!", results); // 断言
}
}
打开 cmd 命令行,进入 HelloWorld 项目根目录(pom.xml 文件所在目录) 执行如下命令,查看根目录变化。
mvn compile
mvn test-compile
mvn clean
mvn clean test
mvn clean pakcage
mvn source:jar
原文:https://www.cnblogs.com/liujiaqi1101/p/13731404.html