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

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.

主站蜘蛛池模板: 唐山市| 天峨县| 靖州| 上犹县| 富川| 九龙县| 杭州市| 前郭尔| 凭祥市| 福贡县| 左贡县| 田林县| 红桥区| 达孜县| 将乐县| 高密市| 莱州市| 专栏| 榆中县| 喀喇沁旗| 焉耆| 庆云县| 邯郸县| 兰州市| 友谊县| 汪清县| 五原县| 红河县| 兴文县| 祁连县| 基隆市| 温宿县| 新野县| 开封市| 佛冈县| 荥阳市| 花莲市| 旬阳县| 益阳市| 吉水县| 通化市|