maven基础命令
一. 编译命令 mvn clean compile
clean -> 告知maven清理输出目录 /target
compile -> 告知maven编译项目主代码
二. 测试命令 mvn clean test
实际执行的为 clean:clean -> resources:resources -> compiler:compiler
-> resources:testResources -> compiler:testCompiler
当涉及的测试代码包括junit的时候,如果使用@test
则pom.xml还需增加相应的依赖包:
<project> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <build> ...... <plugins> <!-- 编译插件:指定编译环境(jre,coding) --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>${project.build.sourceEncoding}</encoding> </configuration> </plugin> ...... </build> </project>
三.打包 mvn clean package
打包好的jar包就可以发布到mvn仓库了
四.安装到本地仓库 mvn clean install
当自己电脑,别的包对该项目有依赖时,且依赖指向本地仓库,需执行该命令