官术网_书友最值得收藏!

Getting started

This application, while conceptually fairly simple, is a bit more complex than what we looked at in the last chapter, in that we will have both, a command line and a graphical interface. The experienced programmer is likely to immediately see the need to share the code between these two interfaces, as DRY (Don't Repeat Yourself) is one of the many hallmarks of a well-designed system. To facilitate this sharing of code, then, we will want to introduce a third module, which provides a library that can be consumed by the other two projects. We will call these modules lib, cli, and gui. Our first step in setting up the project is to create the various Maven POM files to describe the project's structure. The parent POM will look something like this:

    <?xml version="1.0" encoding="UTF-8"?> 
    <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.steeplesoft.dupefind</groupId> 
     <artifactId>dupefind-master</artifactId> 
     <version>1.0-SNAPSHOT</version> 
     <packaging>pom</packaging> 
 
     <modules> 
       <module>lib</module> 
       <module>cli</module> 
       <module>gui</module> 
     </modules> 
 
     <name>Duplicate Finder - Master</name> 
    </project> 

This is a fairly typical POM file. We will start by identifying the project's parent that lets us inherit a number of settings, dependencies, and so on, and avoid having to repeat them in this project. Next, we will define the Maven coordinates for the project. Note that we don't define a version for this project, allowing the parent's version to cascade down. This will allow us to increase the version as needed in one place, and update all of the subprojects implicitly.

The last interesting part of this POM, for those who haven't seen a multi-module project before, is the modules section. The only thing to note here, for those who are new to this, is that each module element refers to a directory name, which is a direct child of the current directory, and should be declared in the order in which they are needed. In our case, the CLI and GUI both depend on the library, so lib goes first. Next, we'll need to create the POM files for each module. Each of these are typical POMs of type jar, so there's no need to include them here. There will be varying dependencies in each, but we'll cover those as the need arises.

主站蜘蛛池模板: 仁化县| 安阳县| 永嘉县| 洪江市| 盖州市| 鄂州市| 金川县| 淅川县| 阿拉善左旗| 云阳县| 玉环县| 桐城市| 眉山市| 克东县| 丰都县| 温泉县| 汪清县| 陆河县| 边坝县| 祁连县| 五家渠市| 岫岩| 本溪市| 天台县| 榆社县| 鄂托克前旗| 郓城县| 班玛县| 湘阴县| 太和县| 岳普湖县| 石屏县| 内江市| 东宁县| 临夏县| 咸宁市| 桐乡市| 车险| 汉寿县| 澜沧| 谢通门县|