maven官方安装及编译教程 | maven官方文档

本文介绍了Maven构建工具中几个常用命令的功能及应用场景:compile用于编译Java源代码;package则进一步进行测试并打包成JAR文件;install命令不仅完成编译、测试和打包,还将项目部署到本地仓库;test命令通过surefire插件执行单元测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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文件时,执行这个命令就会自动开启测试。

参考官方文档 https://spring.io/guides/gs/maven/

转载请注明出处:http://blog.youkuaiyun.com/coder__cs/article/details/79167540
本文出自【elon33的博客

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值