- Mastering Apache Maven 3
- Prabath Siriwardena
- 259字
- 2021-08-06 19:46:38
Convention over configuration
Convention over configuration is one of the main design philosophies behind Apache Maven. Let's go through a few examples.
A complete Maven project can be created using the following code snippet in pom.xml
file:
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.packt</groupId> <artifactId>sample-one</artifactId> <version>1.0.0</version> </project>
Tip
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Copy the previous configuration element and create a pom.xml
file out of it. Then, place it in a directory called chapter-01
and create the following child directories under it:
chapter-01/src/main/java
chapter-01/src/test/java
Now, you can place your Java code under chapter-01/src/main/java
and test cases under chapter-01/src/test/java
. Use the following command to run the Maven build:
$ mvn clean install
This little configuration is tied up with many conventions:
- The Java source code is available at
{base-dir}/src/main/java
- Test cases are available at
{base-dir}/src/test/java
- A JAR file type of artifact is produced
- Compiled class files are copied into
{base-dir}/target/classes
- The final artifact is copied into
{base-dir}/target
- The linkhttp://repo.maven.apache.org/maven2is used as the repository
If someone needs to override the default, conventional behavior of Maven, that is possible too. The following sample pom.xml
file shows how to override some of the preceding default values:
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.packt</groupId> <artifactId>sample-one</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <build> <sourceDirectory>${basedir}/src/main/java</sourceDirectory> <testSourceDirectory>${basedir}/src/test/java </testSourceDirectory> <outputDirectory>${basedir}/target/classes </outputDirectory> </build> </project>
- 極簡算法史:從數學到機器的故事
- SpringMVC+MyBatis快速開發與項目實戰
- Android Application Development Cookbook(Second Edition)
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第2版)
- Python程序設計案例教程
- 小程序開發原理與實戰
- 算法訓練營:提高篇(全彩版)
- HoloLens與混合現實開發
- Kotlin極簡教程
- AMP:Building Accelerated Mobile Pages
- Python Deep Learning
- 軟件測試分析與實踐
- ROS機器人編程實戰
- Java基礎案例教程(第2版)
- FORTRAN程序設計權威指南