maven 常用命令
参考博客 :https://www.cnblogs.com/wkrbky/p/6352188.html
maven用来管理项目,包括项目的创建、编译、打包、运行等。
他提供了一些命令来完成这些功能,配置环境变量后,可以到处运行这些命令,命令会根据当前目录下的pom文件描述,和setting文件描述,调用其他工具实现功能。
常用命令:
mvn compile 编译源代码,创建target目录,生成class文件。 我理解实际是调用jdk的编译程序,只是maven同时管理者项目的信息,告诉编译程序,源文件在哪里,编译后放在哪里。
mvn package 先编译源代码,再将项目打包成jar、war包。 执行后target目录中会多一个jar文件和其他相关文件。
C:\java\jdk\jdk1.8.0_171\bin\java.exe -Dmaven.multiModuleProjectDirectory=D:\MyWork\MyCode\scap\scap-modules\scap-operation -Dmaven.home=D:\MyProgram\apache-maven-3.3.9 -Dclassworlds.conf=D:\MyProgram\apache-maven-3.3.9\bin\m2.conf "-javaagent:D:\MyProgram\idea\IntelliJ IDEA 2018.3\lib\idea_rt.jar=52473:D:\MyProgram\idea\IntelliJ IDEA 2018.3\bin" -Dfile.encoding=UTF-8 -classpath D:\MyProgram\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2018.3 -s D:\MyProgram\apache-maven-3.3.9\conf\settings.xml package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building scap-operation 1.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ scap-operation --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] Copying 7 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ scap-operation --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 31 source files to D:\MyWork\MyCode\scap\scap-modules\scap-operation\target\classes [WARNING] /D:/MyWork/MyCode/scap/scap-modules/scap-operation/src/main/java/com/cnhqd/scap/operation/service/impl/EsServiceImpl.java: D:\MyWork\MyCode\scap\scap-modules\scap-operation\src\main\java\com\cnhqd\scap\operation\service\impl\EsServiceImpl.java使用了未经检查或不安全的操作。 [WARNING] /D:/MyWork/MyCode/scap/scap-modules/scap-operation/src/main/java/com/cnhqd/scap/operation/service/impl/EsServiceImpl.java: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。 [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ scap-operation --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory D:\MyWork\MyCode\scap\scap-modules\scap-operation\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ scap-operation --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ scap-operation --- [INFO] Tests are skipped. [INFO] [INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ scap-operation --- [INFO] Building jar: D:\MyWork\MyCode\scap\scap-modules\scap-operation\target\scap-operation-1.0.jar [INFO] [INFO] --- spring-boot-maven-plugin:1.5.13.RELEASE:repackage (default) @ scap-operation --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 27.583 s [INFO] Finished at: 2019-07-03T10:46:49+08:00 [INFO] Final Memory: 66M/459M [INFO] ------------------------------------------------------------------------ Process finished with exit code 0
mvn install 先执行package操作,再将包放到本地仓库中去。 因为maven知道本地仓库的地址是什么。
mvn clean 清除产生的项目,将某个项目的target目录删除,即删除class文件,只剩下源码文件夹。
其他命令:
mvn validate 验证工程是否正确,所有需要的资源是否可用
C:\java\jdk\jdk1.8.0_171\bin\java.exe -Dmaven.multiModuleProjectDirectory=D:\MyWork\MyCode\scap\scap-modules\scap-operation -Dmaven.home=D:\MyProgram\apache-maven-3.3.9 -Dclassworlds.conf=D:\MyProgram\apache-maven-3.3.9\bin\m2.conf "-javaagent:D:\MyProgram\idea\IntelliJ IDEA 2018.3\lib\idea_rt.jar=56763:D:\MyProgram\idea\IntelliJ IDEA 2018.3\bin" -Dfile.encoding=UTF-8 -classpath D:\MyProgram\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2018.3 -s D:\MyProgram\apache-maven-3.3.9\conf\settings.xml validate
mvn test 运行测试,应该是执行测试方法,没验证。
mvn deploy 上传到私服
--------学习 交流 提升-----------