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

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.

主站蜘蛛池模板: 西藏| 闻喜县| 垦利县| 广灵县| 龙岩市| 蒲江县| 同仁县| 南开区| 安溪县| 滨州市| 达拉特旗| 囊谦县| 桦甸市| 新巴尔虎左旗| 堆龙德庆县| 无极县| 图木舒克市| 邹平县| 昌邑市| 泰和县| 登封市| 博白县| 铜陵市| 东平县| 西和县| 清涧县| 湘潭县| 开平市| 平阴县| 博乐市| 德惠市| 万山特区| 潜江市| 山东| 宜昌市| 芜湖市| 梁河县| 南靖县| 大足县| 额济纳旗| 连江县|