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

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.

主站蜘蛛池模板: 道真| 曲周县| 达州市| 安远县| 鹿邑县| 大田县| 额尔古纳市| 滨海县| 娱乐| 麻江县| 南漳县| 阜宁县| 南充市| 含山县| 璧山县| 乌拉特前旗| 宕昌县| 九龙坡区| 潢川县| 荣昌县| 桓仁| 定襄县| 东安县| 平南县| 济源市| 宜昌市| 宣汉县| 长顺县| 丰宁| 石嘴山市| 新巴尔虎右旗| 临夏市| 宁强县| 大埔区| 孝义市| 稷山县| 车险| 油尖旺区| 吴旗县| 讷河市| 容城县|