- Java 9 Programming Blueprints
- Jason Lee
- 351字
- 2021-07-02 18:56:31
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.
- CMDB分步構建指南
- 造個小程序:與微信一起干件正經事兒
- 編程卓越之道(卷3):軟件工程化
- JIRA 7 Administration Cookbook(Second Edition)
- Web交互界面設計與制作(微課版)
- Python網絡爬蟲從入門到實踐(第2版)
- INSTANT Django 1.5 Application Development Starter
- Linux C編程:一站式學習
- 軟件測試實用教程
- Java設計模式深入研究
- Android技術內幕(系統卷)
- Python程序設計案例教程
- Switching to Angular 2
- ASP.NET 3.5系統開發精髓
- Java無難事:詳解Java編程核心思想與技術