maven书籍--Apache Maven Cookbook(一)maven 使用命令创建、编译java项目

一、创建

使用命令创建项目分几步:

1、打开命令行窗口,比如cmd,把目录切换至想要创建项目地方。

2、执行如下命令:


3、然后是一堆下载

mvn archetype:generate -DgroupId=com.zua.cookbook -DartifactId=simple-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

4、成功后的样子如下:

 

 项目目录如下:

各个目录的功能我就不介绍了.

注意:

  若构建的过程中失败,检查你的maven是否设置了代理服务器

 二、编译

1、打开cmd

2、切换到项目目录下,笔者的目录应该是:C:\adeng\work\maven-parctice\simple-project,其中simple-project是刚刚创建的项目。

3、执行:mvn package

4、若我们没有设置过maven的文件编码,则会出现以下警告:

解释:大致是说,我们没有设置maven的文件编码,然后默认使用了windows系统的默认编码(GBK)

当然目前的影响不大,运行后的结果如下:

5、最后,能看到一个jar文件生成:C:\adeng\work\maven-parctice\simple-project\target\simple-project-1.0-SNAPSHOT.jar

总结:

  在执行:mvn package命令时,其中package参数被解析为maven构建生命周期的一步,maven有自己默认的生命周期,每个生命周期按顺序执行,后面的执行不会跳过前面的生命周期,比如:package的生命周期

  • validate
  • compile
  • test
  • package

validate,验证阶段,根据pom.xml中描述的项目信息进行项目校验

compile,编译阶段,把.java文件编译为.class文件,也就是javac过程

test,测试阶段,执行test源码包下的测试代码,一般是JUnit测试

package,打包阶段,根据pom.xml文件中指定的文件,比如jar,war等

 

看这里,看这里

文章总目录:博客导航

码字不易,尊重原创,原文地址:https://blog.youkuaiyun.com/u_ascend/article/details/80485930

Over 90 hands-on recipes to successfully build and automate development life cycle tasks following Maven conventions and best practices About This Book Understand the features of Apache Maven that makes it a powerful tool for build automation Full of real-world scenarios covering multi-module builds and best practices to make the most out of Maven projects A step-by-step tutorial guide full of pragmatic examples Who This Book Is For If you are a Java developer or a manager who has experience with Apache Maven and want to extend your knowledge, then this is the ideal book for you. Apache Maven Cookbook is for those who want to learn how Apache Maven can be used for build automation. It is also meant for those familiar with Apache Maven, but want to understand the finer nuances of Maven and solve specific problems. What You Will Learn Install Apache Maven successfully on your preferred OS Explore the various features of Apache Maven to build efficient automation tools Discover when and how to use the various Apache Maven plugins Generate and publish your project documentation using Apache Maven Analyze and control code quality and code coverage using Apache Maven Build various types of Java projects as well as other binaries Set up complex projects using the concept of inheritance In Detail Apache Maven offers a comprehensive set of features to build, test, release, and deploy software projects and maintain enterprise development infrastructure. This book is a hands-on guide that enables you to explore the vast potential of Apache Maven, the leading software build tool. You will start off by successfully installing Apache Maven on your favorite OS, and then you will create your first working project. Furthermore, the book walks you through setting up and using Maven with popular Java Integrated Development Environments (IDEs) so you can exploit Maven features to build standard Java applications. Above all, you will also learn to create site reports and documentation for your project along with handling typical build requirements and other advanced Maven usages. Table of Contents Chapter 1: Getting Started Chapter 2: IDE Integration with Maven Chapter 3: Maven Lifecycle Chapter 4: Essential Maven Plugins Chapter 5: Dependency Management Chapter 6: Code Quality Plugins Chapter 7: Reporting and Documentation Chapter 8: Handling Typical Build Requirements Chapter 9: Multimodule Projects Chapter 10: Java Development with Maven Chapter 11: Advanced Maven Usage
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值