- 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.
- Spring Boot開發與測試實戰
- Beginning C++ Game Programming
- 精通API架構:設計、運維與演進
- Java應用開發技術實例教程
- Python數據可視化之Matplotlib與Pyecharts實戰
- Java程序設計:原理與范例
- Getting Started with Gulp
- 青少年信息學競賽
- Kubernetes源碼剖析
- Windows Phone 8 Game Development
- scikit-learn Cookbook(Second Edition)
- C# 7.1 and .NET Core 2.0:Modern Cross-Platform Development(Third Edition)
- Python應用開發技術
- MATLAB 2020 GUI程序設計從入門到精通
- C#網絡編程高級篇之網頁游戲輔助程序設計