- Java 9 Programming By Example
- Peter Verhas
- 513字
- 2021-07-02 23:37:30
Getting started with project structure and build tools
When a project is more complex than a single class, and it usually is, then it is wise to define a project structure. We will have to decide where we store the source files, where the resource files (those that contain some resource for the program, but are not Java source) are, where the .class files should be written by the compiler, and so on. Generally, the structure is mainly the directory setup and the configuration of the tools that perform the build.
The compilation of complex programs cannot be feasibly done using the command line issuing javac commands. If we have 100 Java source files, the compilation will require that many javac commands to be issued. It can be shortened using wild cards, such as javac *.java ,or we can write a simple bash script or a BAT command file that does that. First, it will be just 100 lines, each compiling one source Java file to class file. Then, we will realize that it is only time, CPU, and power consuming to compile the files that are not changed since the last compilations so we can add some bash programming that checks the time stamp on the source and generated files. Then, we will probably realize that... whatever. At the end, we will end up with a tool that is essentially a build tool. Build tools are available ready made; it is not worth reinventing the wheel.
Instead of creating one, we will use a build tool that is ready. There are a few of them that can be found at https://en.wikipedia.org/wiki/List_of_build_automation_software. In this chapter, we will use one called Maven; however, before jumping into the details of this tool, we will look at some other tools that you are likely to meet as a Java professional in enterprise projects.
In the following sections, we will discuss a bit of the four build tools:
- Make
- Ant
- Maven
- Gradle
We will mention Make only briefly because it is not used in Java environments these days. However, Make was the first build tool, and many ideas that modern Java build tools are based on come from the good old make. You, as a professional Java developer, should also be familiar with Make so that you will not freak out if you happen to see the use of it in a project for some purpose, and can know what it is and where its detailed documentation can be found.
Ant was the first build tool widely used for Java many years ago, and it is still used in many projects.
Maven is newer than Ant, and it uses a different approach. We will look at it in detail. Maven is also the official build tool of the Apache software foundation for the Java project. We will also use Maven as a build tool in this chapter.
Gradle is even newer, and it has started to catch up to Maven these days. We will use this tool in later chapters in more detail.
- Android Jetpack開發:原理解析與應用實戰
- LabVIEW Graphical Programming Cookbook
- 騰訊iOS測試實踐
- Programming ArcGIS 10.1 with Python Cookbook
- Mastering C# Concurrency
- INSTANT Mercurial SCM Essentials How-to
- Reactive Programming With Java 9
- The HTML and CSS Workshop
- Python+Tableau數據可視化之美
- 計算機應用基礎項目化教程
- 算法圖解
- Mastering Android Studio 3
- Java高并發編程詳解:深入理解并發核心庫
- 編程的原則:改善代碼質量的101個方法
- Unity 5 Game Optimization