maven 构建Java应用及其他应用的入门教程,建议读者参考Spring的官方文档 【点击跳转】
这里主要说明下,我们maven中编译Java代码的几个关键命令的说明,首先贴出maven帮助文档中对这几个命令的描述:
mvn compile
This will run Maven, telling it to execute the compile goal. When it’s finished, you should find the compiled .class files in the target/classes directory.
mvn package
The package goal will compile your Java code, run any tests, and finish by packaging the code up in a JAR file within the target directory. The name of the JAR file will be based on the project’s and . For example, given the minimal pom.xml file from before, the JAR file will be named gs-maven-0.1.0.jar.
mvn install
The install goal will compile, test, and package your project’s code and then copy it into the local dependency repository, ready for another project to reference it as a dependency.
mvn test
Maven uses a plugin called “surefire” to run unit tests. The default configuration of this plugin compiles and runs all classes in src/test/java with a name matching *Test. You can run the tests on the command line like this
总结起来就是,如果对于Java文件的编译只是想得到其class文件,就直接用mvn compile
命令,如果想要编译出来的项目文件作为本地库依赖给其他项目使用时,则需要用mvn install
,对于第三种mvn package
命令,则是在需要将项目打包到其他平台运行时使用,最后mvn test
命令则是和junit测试包相关的,当./test/java文件目录下有以*Test.java结尾的Java文件时,执行这个命令就会自动开启测试。
转载请注明出处:http://blog.youkuaiyun.com/coder__cs/article/details/79167540
本文出自【elon33的博客】