- Building a RESTful Web Service with Spring
- Ludovic Dewailly
- 409字
- 2021-07-09 21:44:51
Apache Maven
Maven is an open-source software project management tool. It was born out of the need to simplify Ant-based builds and it favors convention over configuration. In more concrete terms, it offers out of the box support for typical workflows, such as building Java web applications, provided one follows its conventions. However, customizing the build process can prove challenging, and many of its detractors point this design choice out as the main motivation for not using Maven.
Note
More information on Maven can be found at https://maven.apache.org.
While Maven offers many features, they are beyond the scope of this chapter. We will focus on its support for building Java web applications.
The following POM (Project Object Model) file illustrates how a project can be declared with Maven (in a file called pom.xml):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.packtpub.rest-with-spring</groupId> <artifactId>rest-with-spring</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> </project>
This pom.xml file defines a project with a group identifier, artifact identifier, and version. It also describes how the resulting application will be packaged (as a WAR file in this case).
Developers are free to choose their versioning schemes. However, Maven works best with a version of the form x.y
, where x
is the major version number and y
the minor version number.
Dependency management in Apache Maven
One build feature that makes development much easier is dependency management. It alleviates the need to manually download third-party libraries and package them with the application. Maven has robust dependency management based on artifact repositories.
Tip
The main repository for Maven is called the Central Repository and can be searched on at http://maven.org.
To declare dependencies, the sample POM file that was presented in the previous section can be amended in the following fashion:
// content omitted for readability purposes <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.1.9.Final</version> </dependency> <!-- Test Dependencies --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> </dependencies> </project>
The <dependencies>
element in the amended POM file declares two dependencies:
Another build tool that has gathered a lot of popularity is Gradle and it is discussed in the next section
- UML和模式應(yīng)用(原書第3版)
- 前端跨界開發(fā)指南:JavaScript工具庫(kù)原理解析與實(shí)戰(zhàn)
- Learning Spring 5.0
- ASP.NET Core Essentials
- 實(shí)戰(zhàn)Java程序設(shè)計(jì)
- Java開發(fā)入行真功夫
- Android底層接口與驅(qū)動(dòng)開發(fā)技術(shù)詳解
- PHP+MySQL+Dreamweaver動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(第3版)
- Android驅(qū)動(dòng)開發(fā)權(quán)威指南
- C# Multithreaded and Parallel Programming
- Web性能實(shí)戰(zhàn)
- 現(xiàn)代C:概念剖析和編程實(shí)踐
- 石墨烯改性塑料
- Learning Concurrency in Python
- WordPress Search Engine Optimization(Second Edition)