Just about every Java project that I've seen either uses Maven or Ant. They are fine tools and I think just about any project can use them. But what ever happened to make? It's used for a variety of non-Java projects and can easily handle Java. Sure you have to download make.exe if you use Windows, but Ant and Maven also don't come with the JDK.
我看到的几乎每个Java项目都使用Maven或Ant。它们是很好的工具,我认为任何项目都可以使用它们。但是到底发生了什么?它用于各种非Java项目,可以轻松地处理Java。你一定要下载make。如果您使用Windows,则使用exe,但是Ant和Maven也不附带JDK。
Is there some fundamental flaw with make when used with Java? Is it just because Ant and Maven are written in Java?
在使用Java时,make是否存在一些根本缺陷?仅仅因为Ant和Maven是用Java编写的吗?
17 个解决方案
#1
167
The fundamental issue with Make and Java is that Make works on the premise that you have specify a dependency, and then a rule to resolve that dependency.
Make和Java的基本问题是,在指定依赖项的前提下进行工作,然后使用规则来解决依赖关系。
With basic C, that typically "to convert a main.c file to a main.o file, run "cc main.c".
用基本的C语言,通常是“转换主键”。c文件到主文件。o文件,运行“cc main.c”。
You can do that in java, but you quickly learn something.
你可以用java来做,但是你很快就会学到一些东西。
Mostly that the javac compiler is slow to start up.
大多数情况下,javac编译器启动缓慢。
The difference between:
之间的区别:
javac Main.java
javac This.java
javac That.java
javac Other.java
and
和
javac Main.java This.java That.java Other.java
is night and day.
是日夜。
Exacerbate that with hundreds of classes, and it just becomes untenable.
用几百个类来加重它,它就变得站不住脚了。
Then you combine that with the fact that java tends to be organized as groups of files in directories, vs C and others which tend towards a flatter structure. Make doesn't have much direct support to working with hierarchies of files.
然后,您将其与java倾向于组织成目录中的文件组、vs C和其他倾向于扁平结构的事实结合起来。Make对处理文件的层次结构没有太多的直接支持。
Make also isn't very good at determining what files are out of date, at a collection level.
Make在收集级别上也不太擅长确定哪些文件是过时的。
With Ant, it will go through and sum up all of the files that are out of date, and then compile them in one go. Make will simply call the java compiler on each individual file. Having make NOT do this requires enough external tooling to really show that Make is not quite up to the task.
使用Ant,它将遍历并总结所有过时的文件,然后一次性编译它们。Make仅仅调用每个文件上的java编译器。如果不这样做,就需要足够的外部工具来显示make并不能完全胜任这个任务。
That's why alternatives like Ant and Maven rose up.
这就是为什么像Ant和Maven这样的替代选择出现了。
#2
30
The venerable make
program handles separately compiled languages like C and C++ reasonably well. You compile a module, it uses #include
to pull in the text of other include files, and writes a single object file as output. The compiler is very much a one-at-a-time system, with a separate linking step to bind the object files into an executable binary.
值得尊敬的make程序可以很好地处理像C和c++这样的编译语言。您可以编译一个模块,它使用#include来提取其他include文件的文本,并将一个对象文件作为输出写入。编译器是一个非常多的系统,它有一个单独的连接步骤,将目标文件绑定到一个可执行的二进制文件中。
However, in Java, the compiler has to actually compile other classes that you import with import
. Although it would be possible to write something that generated all the necessary dependencies from Java source code, so that make
would build classes in the correct order one at a time, this still wouldn't handle cases such as circular dependencies.
但是,在Java中,编译器实际上必须编译您导入的其他类。虽然可以编写一些从Java源代码中生成所有必要依赖项的东西,这样make就可以一次构建一个正确的类,但这仍然不能处理诸如循环依赖这样的情况。
The Java compiler can also be more efficient by caching the compiled results of other classes while compiling further classes that depend on the results of ones already compiled. This sort of automatic dependency evaluation is not really possible with make
alone.
Java编译器还可以通过缓存其他类的编译结果来提高效率,同时编译依赖于已经编译的类的结果的进一步类。这种自动依赖评估是不可能单独使用make的。
#3
27
The question is based on an incorrect assumption: a non-trivial number of developers do use make
. See Java Build Tools: Ant vs. Maven. As for why a developer wouldn't use make
: many developers either have never used make
, or used it and hated it with a fire that burns hotter than a thousand suns. As such, they use alternative tools.
这个问题基于一个错误的假设:大量的开发人员使用make。参见Java构建工具:Ant vs. Maven。至于为什么开发人员不使用make:许多开发人员要么从未使用过make,要么使用过make,讨厌它,因为它燃烧的火焰比1000个太阳还要热。因此,他们使用替代工具。
#4
19
Actually, make can handle the recompilation in one command of all outdated java files. Change the first line if you don't want to compile all files in the directory or want a specific order...
实际上,make可以处理所有过时java文件的重新编译。如果您不想编译目录中的所有文件或想要一个特定的顺序,请更改第一行……
JAVA_FILES:=$(wildcard *.java)
#
# the rest is independent of the directory
#
JAVA_CLASSES:=$(patsubst %.java,%.class,$(JAVA_FILES))
.PHONY: classes
LIST:=
classes: $(JAVA_CLASSES)
if [ ! -z "$(LIST)" ] ; then \
javac $(LIST) ; \
fi
$(JAVA_CLASSES) : %.class : %.java
$(eval LIST+=$$<)
#5
17
All the other answers about the technical merits of each are true. Ant
and Maven
may be better suited to Java than make, or as Hank Gay points out, they may not :)
所有其他关于每个技术优点的答案都是正确的。Ant和Maven可能比make更适合Java,或者正如汉克•盖伊(Hank Gay)所指出的,它们可能不适合Java:
However, you asked if it matters that Ant and Maven are written in Java. Although on * we don't consider such thoughts (closed! not-programming-related! etc.), OF COURSE THAT'S PART OF THE THING. On rails we use Rake, C dudes use make, and in Java we use Ant and Maven. While it's true that the Ant or Maven developers will look after the Java developer perhaps better than others, there's also another question: what do you write Ant tasks in? Java. If you're a Java developer, that's an easy fit.
但是,您会问,用Java编写Ant和Maven是否重要。虽然在*上我们不考虑这样的想法(关闭!not-programming-related !等等),当然这是事情的一部分。在rails中我们使用Rake, C dudes使用make,在Java中我们使用Ant和Maven。虽然Ant或Maven开发人员确实会比其他开发人员更好地照顾Java开发人员,但还有一个问题:您在Ant中编写什么任务?Java。如果您是一个Java开发人员,那就很容易适应。
So yeah, part of it is to use tools written in the language you are tooling.
所以,是的,一部分是用你所使用的语言编写的工具。
#6
12
Ant and later Maven were designed to solve some headaches caused by Make
( while creating new ones in the process ) It is just evolution.
Ant和后来的Maven被设计用来解决Make引起的一些头痛问题(在这个过程中创建新的),这只是进化。
...Soon thereafter, several open source Java projects realized that Ant could solve the problems they had with Makefiles....
…不久之后,几个开放源码Java项目意识到蚂蚁可以解决他们的问题与makefile ....
From http://ant.apache.org/faq.html#history
从http://ant.apache.org/faq.html历史
Whether they solve anything or just create an extra format to learn is a subjective topic. The truth is that's pretty much the history of every new invention: The creator says it solves a lot of problems and the original users say those are virtues.
无论他们解决了什么问题,还是仅仅创建了一个额外的学习格式,这都是一个主观的话题。事实上,这几乎是每一项新发明的历史:创造者说它解决了许多问题,而最初的用户说这些是美德。
The main advantage it has, is the possibility to integrate with java.
它的主要优点是可以与java集成。
I guess a similar history would be with rake
for instance.
我猜类似的历史会发生在rake身上。
#7
9
One of the major issues solved by Maven (and Ivy-enabled Ant setups) over make is automated dependency resolution and downloading of your dependency jars.
Maven(和启用了ivy的Ant设置)解决的主要问题之一是自动化依赖项解析和下载依赖项jar。
#8
6
I think the most likely explanation is that several factors discouraged the use of make within the Java community in a critical period of time (the late 1990s):
我认为最有可能的解释是,在一个关键时期(上世纪90年代末),有几个因素阻碍了Java社区使用make:
- Because Java encompasses multiple platforms, Java programmers in general were not as adept at Unix tools as were programmers generally confined to a Unix environment (e.g., C and Perl programmers). Note that this is IN GENERAL. Without a doubt there are and were gifted Java programmers with a deep understanding of Unix.
- 因为Java包含多个平台,所以Java程序员通常不像通常局限于Unix环境(例如,C和Perl程序员)的程序员那样擅长Unix工具。注意这是一般的。毫无疑问,有并且有天赋的Java程序员对Unix有深刻的理解。
- Consequently they were less adept at make and didn't know how to use make effectively.
- 因此,他们不太擅长制作,也不知道如何有效地使用制作。
- While it is possible to write a short and simple Makefile that compiles Java efficiently, extra care is required to do so in a platform-independent way.
- 虽然可以编写一个简短的、简单的、高效编译Java的Makefile,但是需要特别注意以独立于平台的方式进行编译。
- Consequently there was an appetite for an intrinsically platform-independent build tool.
- 因此,人们对本质上独立于平台的构建工具产生了兴趣。
- It was in this environment that Ant and later Maven were created.
- 在这个环境中,Ant和后来的Maven被创建。
In short, while make most certainly can be used for Java projects, there was a moment of opportunity to make it the de facto Java build tool. That moment has passed.
简而言之,尽管make肯定可以用于Java项目,但有机会让它成为事实上的Java构建工具。那一刻已经过去了。
#9
5
Make scripts tend to be inherently platform dependent. Java is supposed to be platform independent. Therefore having a build system that only works on one platform for a multi-platform sourcebase is kindof a problem.
使脚本天生依赖于平台。Java应该是独立于平台的。因此,有一个只在一个平台上为一个多平台的sourcebase工作的构建系统是一个问题。
#10
4
Unless I am no one the assumption no one is (mis)using make for java is wrong.
除非我不是一个人,否则没有人会使用make来代替java。
"Managing Projects with GNU Make" (available under GFDL) contains a complete chapter dedicated to using make
with java projects.
“使用GNU Make管理项目”(可以在GFDL下获得)包含一个完整的章节,专门用于使用java项目中的Make。
As it contains a long (and hopefully fair) list of the pros and cons of using make instead of other tools you might want to take a look there. (see: http://oreilly.com/catalog/make3/book/)
由于它包含了一长串(希望是公平的)关于使用make而不是其他工具的优缺点的列表,您可能想在这里查看一下。(参见:http://oreilly.com/catalog/make3/book/)
#11
3
Ant is an XML configuration oriented improvement over Makefiles and Maven is a dependency build tool improvement over Ant. Some projects use all three. I think the JDK projects used to use a mix of makefiles and ant.
Ant是一个针对makefile的XML配置改进,而Maven是一个依赖于Ant构建工具的改进。有些项目使用这三种方法。我认为JDK项目使用了makefile和ant的混合。
#12
3
Short answer: Because make
isn't good. Even on the C front you see many alternatives popping up.
简单回答:因为做不好。即使是在C前面,你也能看到很多替代方案。
Long answer: make
has several flaws that make it barely suitable for compiling C, and unsuitable at all for compiling Java. You can force it to compile Java, if you want, but expect running into issues, some of which do not have a suitable solution or workaround. Here are a few:
Long answer: make有几个缺陷,使得它几乎不适合编译C,并且不适合编译Java。如果您愿意,可以强制它编译Java,但是可能会遇到一些问题,其中一些问题没有合适的解决方案或解决方案。这里有几个:
Dependency resolution
make
inherently expects files to have a tree-like dependency on each other, in which one file is the output of building several others. This already backfires in C when dealing with header files. make
requires a make
-specific include file to be generated to represent the dependency of a C file on its header files, so a change to the latter would cause the prior to be rebuilt. However, since the C file itself isn't recreated (merely rebuilt), make often requires specifying the target as .PHONY
. Fortunately, GCC supports generating those files automatically.
make固有地期望文件具有像树一样的依赖关系,其中一个文件是构建几个其他文件的输出。在处理头文件时,这已经在C中起了反作用。make需要生成一个特定于make的include文件,以表示C文件对其头文件的依赖关系,因此对后者的更改将导致在重新构建之前。但是,由于C文件本身没有被重新创建(只是重新构建),make常常需要将目标指定为. phony。幸运的是,GCC支持自动生成这些文件。
In Java, dependency can be circular, and there's no tool for auto-generating class dependencies in make
format. ant
's Depend
task can, instead, read the class file directly, determine which classes it imports, and delete the class file if any of them are out of date. Without this, any non-trivial dependency may result in you being forced to use repeated clean builds, removing any advantage of using a build tool.
在Java中,依赖关系可以是循环的,并且没有工具在make格式中自动生成类依赖关系。相反,ant的Depend任务可以直接读取类文件,确定它导入的类,并在任何类文件过时时删除类文件。如果没有这些,任何重要的依赖项都可能导致您*使用重复的干净构建,从而消除使用构建工具的任何优势。
Spaces in filenames
While neither Java nor C encourage using spaces in your source code filenames, in make
this can be problem even if the spaces are in the file path. Consider, for example, if your source code exists in C:\My Documents\My Code\program\src
. This would be enough to break make
. This is because make
treats filenames as strings. ant
treats paths as special objects.
虽然Java和C都不鼓励在源代码文件名中使用空格,但这样做可能会造成问题,即使空格位于文件路径中。考虑一下,例如,如果您的源代码存在于C:\我的文档\我的代码\程序\src中。这就足够打破常规了。这是因为将文件名作为字符串处理。ant将路径视为特殊对象。
Scanning files for build
make
requires explicitly setting which files are to be built for each target. ant
allows specifying a folder which is to be auto-scanned for source files. It may seem like a minor convenience, but consider that in Java each new class requires a new file. Adding files to the project can become a big hassle fast.
make需要显式地设置要为每个目标构建哪些文件。ant允许指定要自动扫描源文件的文件夹。这看起来似乎有点小方便,但请考虑在Java中,每个新类都需要一个新文件。向项目添加文件很快就会成为一个大麻烦。
And the biggest problem with make
:
最大的问题是
make is POSIX-dependent
Java's motto is "compile once run everywhere". But restricting that compilation to POSIX-based systems, in which Java support is actually the worst, is not the intention.
Java的座右铭是“编译一次,到处运行”。但是,将编译限制在基于posix的系统(其中Java支持实际上是最糟糕的)并不是初衷。
Build rules in make
are essentially small bash
scripts. Even though there is a port of make
to Windows, for it to work properly, it has to be bundled with a port of bash
, which includes a POSIX emulation layer for the file system.
make中的构建规则本质上是小型bash脚本。即使有一个到Windows的make端口,要让它正常工作,它也必须与bash的端口绑定,该端口包括文件系统的POSIX仿真层。
This comes in two varieties:
这有两种类型:
-
MSYS
which tries to limit the POSIX translation to file paths, and can therefore have unpleasant gotchas when running external tools not made especially for it.MSYS试图将POSIX转换限制为文件路径,因此在运行外部工具时,可能会遇到不愉快的问题。
-
cygwin
which provides a complete POSIX emulation. The resulting programs, however, tend to still rely on that emulation layer.cygwin提供一个完整的POSIX仿真。然而,生成的程序往往仍然依赖于仿真层。
For that reason, on Windows, the standard build tool isn't even make
at all, but rather MSBuild
, which is also an XML-based tool, closer in principle to ant
.
出于这个原因,在Windows上,标准的构建工具甚至根本就没有生成,而是MSBuild,它也是一种基于xml的工具,在原则上更接近ant。
By contrast, ant
is built in Java, can run everywhere, and contains internal tools, called "tasks", for manipulating files and executing commands in a platform-independent way. It's sufficiently versatile that you can actually have an easier time building a C program in Windows using ant
than using make
.
相比之下,ant是用Java构建的,可以在任何地方运行,并且包含内部工具,称为“任务”,用于以独立于平台的方式操作文件和执行命令。它的用途非常广泛,您可以在Windows中使用ant比使用make更容易地构建一个C程序。
And one last minor one:
最后一个小问题:
Even C programs don't use make natively
You may not initially notice this, but C programs generally aren't shipped with a Makefile
. They are shipped with a CMakeLists.txt
, or a bash
configuration script, which generates the actual Makefile
. By contrast, the source of a Java program built using ant
is shipped with an ant
script pre-built. A Makefile
is a product of other tools - That's how much make
is unsuitable to be a build tool on its own. ant
is standalone, and deals with everything you need for your Java build process, without any additional requirements or dependencies.
您可能最初没有注意到这一点,但是C程序通常不会附带Makefile。他们与顾客一起装运。txt,或bash配置脚本,生成实际的Makefile。相比之下,使用ant构建的Java程序的源代码是通过预先构建的ant脚本发送的。Makefile是其他工具的产物——这就是make本身不适合作为构建工具的原因。ant是独立的,并处理您的Java构建过程所需的一切,而不需要任何额外的需求或依赖。
When you run ant
on any platform, it Just Works(tm). You can't get that with make
. It's incredibly platform and configuration dependent.
当您在任何平台上运行ant时,它都会正常工作(tm)。你不能用make得到它。它非常依赖于平台和配置。
#13
1
One big reason is that both Ant and Maven (and most java targeted SCM, CI and IDE tools) are written in java by/for java developers. This makes it simpler to integrate into your development environment and allows other tools such as the IDE and CI servers to integrate portions of the ant/maven libraries within the build/deployment infrastructure.
一个重要的原因是Ant和Maven(以及大多数针对java的SCM、CI和IDE工具)都是java开发人员编写的。这使得集成到开发环境中更加简单,并允许其他工具(如IDE和CI服务器)在构建/部署基础结构中集成部分ant/maven库。
#14
1
Once upon a time I worked on a Java project that used gmake. My recollection is hazy but IIRC we had a hard time dealing with the package directory structure that javac expects. I also remember that building JAR files was a hassle unless you had something trivial.
曾几何时,我在一个使用gmake的Java项目上工作。我的记忆是模糊的,但是我们很难处理javac所期望的包目录结构。我还记得构建JAR文件是一件麻烦事,除非你有一些琐碎的事情。
#15
0
Ant and Maven approach the build dependency graph and the management of it from a more 'modern' view... But as Oscar says, they created their own problems while attempting to address the old problems with make.
Ant和Maven通过更“现代”的视角来处理构建依赖关系图和管理。但正如奥斯卡所说,他们在试图解决make的旧问题的同时,也制造了自己的问题。
#16
0
I've never used GNU Make for Java projects, but I used to use jmk. Sadly it hasn't been updated since 2002.
我从未在Java项目中使用GNU Make,但是我曾经使用jmk。遗憾的是,它自2002年以来就没有更新过。
It had some Java-specific functionality but was small enough to include in your source tarball without significantly increasing its size.
它有一些特定于java的功能,但是足够小,可以包含在源tarball中,而不会显著增加它的大小。
Nowadays I just assume any Java developer I share code with has Ant installed.
现在,我假设与我共享代码的任何Java开发人员都安装了Ant。
#17
0
ApacheAnt isn't anything like Make. Make is about describing dependencies between files, and how to build files. Ant is about dependencies between "tasks", and is really more of a way of gluing build scripts together.
ApacheAnt不像Make。Make是描述文件之间的依赖关系,以及如何构建文件。Ant是关于“任务”之间的依赖关系,实际上它更像是一种将构建脚本粘合在一起的方法。
it may helps you AntVsMake
它可能对你有所帮助
#1
167
The fundamental issue with Make and Java is that Make works on the premise that you have specify a dependency, and then a rule to resolve that dependency.
Make和Java的基本问题是,在指定依赖项的前提下进行工作,然后使用规则来解决依赖关系。
With basic C, that typically "to convert a main.c file to a main.o file, run "cc main.c".
用基本的C语言,通常是“转换主键”。c文件到主文件。o文件,运行“cc main.c”。
You can do that in java, but you quickly learn something.
你可以用java来做,但是你很快就会学到一些东西。
Mostly that the javac compiler is slow to start up.
大多数情况下,javac编译器启动缓慢。
The difference between:
之间的区别:
javac Main.java
javac This.java
javac That.java
javac Other.java
and
和
javac Main.java This.java That.java Other.java
is night and day.
是日夜。
Exacerbate that with hundreds of classes, and it just becomes untenable.
用几百个类来加重它,它就变得站不住脚了。
Then you combine that with the fact that java tends to be organized as groups of files in directories, vs C and others which tend towards a flatter structure. Make doesn't have much direct support to working with hierarchies of files.
然后,您将其与java倾向于组织成目录中的文件组、vs C和其他倾向于扁平结构的事实结合起来。Make对处理文件的层次结构没有太多的直接支持。
Make also isn't very good at determining what files are out of date, at a collection level.
Make在收集级别上也不太擅长确定哪些文件是过时的。
With Ant, it will go through and sum up all of the files that are out of date, and then compile them in one go. Make will simply call the java compiler on each individual file. Having make NOT do this requires enough external tooling to really show that Make is not quite up to the task.
使用Ant,它将遍历并总结所有过时的文件,然后一次性编译它们。Make仅仅调用每个文件上的java编译器。如果不这样做,就需要足够的外部工具来显示make并不能完全胜任这个任务。
That's why alternatives like Ant and Maven rose up.
这就是为什么像Ant和Maven这样的替代选择出现了。
#2
30
The venerable make
program handles separately compiled languages like C and C++ reasonably well. You compile a module, it uses #include
to pull in the text of other include files, and writes a single object file as output. The compiler is very much a one-at-a-time system, with a separate linking step to bind the object files into an executable binary.
值得尊敬的make程序可以很好地处理像C和c++这样的编译语言。您可以编译一个模块,它使用#include来提取其他include文件的文本,并将一个对象文件作为输出写入。编译器是一个非常多的系统,它有一个单独的连接步骤,将目标文件绑定到一个可执行的二进制文件中。
However, in Java, the compiler has to actually compile other classes that you import with import
. Although it would be possible to write something that generated all the necessary dependencies from Java source code, so that make
would build classes in the correct order one at a time, this still wouldn't handle cases such as circular dependencies.
但是,在Java中,编译器实际上必须编译您导入的其他类。虽然可以编写一些从Java源代码中生成所有必要依赖项的东西,这样make就可以一次构建一个正确的类,但这仍然不能处理诸如循环依赖这样的情况。
The Java compiler can also be more efficient by caching the compiled results of other classes while compiling further classes that depend on the results of ones already compiled. This sort of automatic dependency evaluation is not really possible with make
alone.
Java编译器还可以通过缓存其他类的编译结果来提高效率,同时编译依赖于已经编译的类的结果的进一步类。这种自动依赖评估是不可能单独使用make的。
#3
27
The question is based on an incorrect assumption: a non-trivial number of developers do use make
. See Java Build Tools: Ant vs. Maven. As for why a developer wouldn't use make
: many developers either have never used make
, or used it and hated it with a fire that burns hotter than a thousand suns. As such, they use alternative tools.
这个问题基于一个错误的假设:大量的开发人员使用make。参见Java构建工具:Ant vs. Maven。至于为什么开发人员不使用make:许多开发人员要么从未使用过make,要么使用过make,讨厌它,因为它燃烧的火焰比1000个太阳还要热。因此,他们使用替代工具。
#4
19
Actually, make can handle the recompilation in one command of all outdated java files. Change the first line if you don't want to compile all files in the directory or want a specific order...
实际上,make可以处理所有过时java文件的重新编译。如果您不想编译目录中的所有文件或想要一个特定的顺序,请更改第一行……
JAVA_FILES:=$(wildcard *.java)
#
# the rest is independent of the directory
#
JAVA_CLASSES:=$(patsubst %.java,%.class,$(JAVA_FILES))
.PHONY: classes
LIST:=
classes: $(JAVA_CLASSES)
if [ ! -z "$(LIST)" ] ; then \
javac $(LIST) ; \
fi
$(JAVA_CLASSES) : %.class : %.java
$(eval LIST+=$$<)
#5
17
All the other answers about the technical merits of each are true. Ant
and Maven
may be better suited to Java than make, or as Hank Gay points out, they may not :)
所有其他关于每个技术优点的答案都是正确的。Ant和Maven可能比make更适合Java,或者正如汉克•盖伊(Hank Gay)所指出的,它们可能不适合Java:
However, you asked if it matters that Ant and Maven are written in Java. Although on * we don't consider such thoughts (closed! not-programming-related! etc.), OF COURSE THAT'S PART OF THE THING. On rails we use Rake, C dudes use make, and in Java we use Ant and Maven. While it's true that the Ant or Maven developers will look after the Java developer perhaps better than others, there's also another question: what do you write Ant tasks in? Java. If you're a Java developer, that's an easy fit.
但是,您会问,用Java编写Ant和Maven是否重要。虽然在*上我们不考虑这样的想法(关闭!not-programming-related !等等),当然这是事情的一部分。在rails中我们使用Rake, C dudes使用make,在Java中我们使用Ant和Maven。虽然Ant或Maven开发人员确实会比其他开发人员更好地照顾Java开发人员,但还有一个问题:您在Ant中编写什么任务?Java。如果您是一个Java开发人员,那就很容易适应。
So yeah, part of it is to use tools written in the language you are tooling.
所以,是的,一部分是用你所使用的语言编写的工具。
#6
12
Ant and later Maven were designed to solve some headaches caused by Make
( while creating new ones in the process ) It is just evolution.
Ant和后来的Maven被设计用来解决Make引起的一些头痛问题(在这个过程中创建新的),这只是进化。
...Soon thereafter, several open source Java projects realized that Ant could solve the problems they had with Makefiles....
…不久之后,几个开放源码Java项目意识到蚂蚁可以解决他们的问题与makefile ....
From http://ant.apache.org/faq.html#history
从http://ant.apache.org/faq.html历史
Whether they solve anything or just create an extra format to learn is a subjective topic. The truth is that's pretty much the history of every new invention: The creator says it solves a lot of problems and the original users say those are virtues.
无论他们解决了什么问题,还是仅仅创建了一个额外的学习格式,这都是一个主观的话题。事实上,这几乎是每一项新发明的历史:创造者说它解决了许多问题,而最初的用户说这些是美德。
The main advantage it has, is the possibility to integrate with java.
它的主要优点是可以与java集成。
I guess a similar history would be with rake
for instance.
我猜类似的历史会发生在rake身上。
#7
9
One of the major issues solved by Maven (and Ivy-enabled Ant setups) over make is automated dependency resolution and downloading of your dependency jars.
Maven(和启用了ivy的Ant设置)解决的主要问题之一是自动化依赖项解析和下载依赖项jar。
#8
6
I think the most likely explanation is that several factors discouraged the use of make within the Java community in a critical period of time (the late 1990s):
我认为最有可能的解释是,在一个关键时期(上世纪90年代末),有几个因素阻碍了Java社区使用make:
- Because Java encompasses multiple platforms, Java programmers in general were not as adept at Unix tools as were programmers generally confined to a Unix environment (e.g., C and Perl programmers). Note that this is IN GENERAL. Without a doubt there are and were gifted Java programmers with a deep understanding of Unix.
- 因为Java包含多个平台,所以Java程序员通常不像通常局限于Unix环境(例如,C和Perl程序员)的程序员那样擅长Unix工具。注意这是一般的。毫无疑问,有并且有天赋的Java程序员对Unix有深刻的理解。
- Consequently they were less adept at make and didn't know how to use make effectively.
- 因此,他们不太擅长制作,也不知道如何有效地使用制作。
- While it is possible to write a short and simple Makefile that compiles Java efficiently, extra care is required to do so in a platform-independent way.
- 虽然可以编写一个简短的、简单的、高效编译Java的Makefile,但是需要特别注意以独立于平台的方式进行编译。
- Consequently there was an appetite for an intrinsically platform-independent build tool.
- 因此,人们对本质上独立于平台的构建工具产生了兴趣。
- It was in this environment that Ant and later Maven were created.
- 在这个环境中,Ant和后来的Maven被创建。
In short, while make most certainly can be used for Java projects, there was a moment of opportunity to make it the de facto Java build tool. That moment has passed.
简而言之,尽管make肯定可以用于Java项目,但有机会让它成为事实上的Java构建工具。那一刻已经过去了。
#9
5
Make scripts tend to be inherently platform dependent. Java is supposed to be platform independent. Therefore having a build system that only works on one platform for a multi-platform sourcebase is kindof a problem.
使脚本天生依赖于平台。Java应该是独立于平台的。因此,有一个只在一个平台上为一个多平台的sourcebase工作的构建系统是一个问题。
#10
4
Unless I am no one the assumption no one is (mis)using make for java is wrong.
除非我不是一个人,否则没有人会使用make来代替java。
"Managing Projects with GNU Make" (available under GFDL) contains a complete chapter dedicated to using make
with java projects.
“使用GNU Make管理项目”(可以在GFDL下获得)包含一个完整的章节,专门用于使用java项目中的Make。
As it contains a long (and hopefully fair) list of the pros and cons of using make instead of other tools you might want to take a look there. (see: http://oreilly.com/catalog/make3/book/)
由于它包含了一长串(希望是公平的)关于使用make而不是其他工具的优缺点的列表,您可能想在这里查看一下。(参见:http://oreilly.com/catalog/make3/book/)
#11
3
Ant is an XML configuration oriented improvement over Makefiles and Maven is a dependency build tool improvement over Ant. Some projects use all three. I think the JDK projects used to use a mix of makefiles and ant.
Ant是一个针对makefile的XML配置改进,而Maven是一个依赖于Ant构建工具的改进。有些项目使用这三种方法。我认为JDK项目使用了makefile和ant的混合。
#12
3
Short answer: Because make
isn't good. Even on the C front you see many alternatives popping up.
简单回答:因为做不好。即使是在C前面,你也能看到很多替代方案。
Long answer: make
has several flaws that make it barely suitable for compiling C, and unsuitable at all for compiling Java. You can force it to compile Java, if you want, but expect running into issues, some of which do not have a suitable solution or workaround. Here are a few:
Long answer: make有几个缺陷,使得它几乎不适合编译C,并且不适合编译Java。如果您愿意,可以强制它编译Java,但是可能会遇到一些问题,其中一些问题没有合适的解决方案或解决方案。这里有几个:
Dependency resolution
make
inherently expects files to have a tree-like dependency on each other, in which one file is the output of building several others. This already backfires in C when dealing with header files. make
requires a make
-specific include file to be generated to represent the dependency of a C file on its header files, so a change to the latter would cause the prior to be rebuilt. However, since the C file itself isn't recreated (merely rebuilt), make often requires specifying the target as .PHONY
. Fortunately, GCC supports generating those files automatically.
make固有地期望文件具有像树一样的依赖关系,其中一个文件是构建几个其他文件的输出。在处理头文件时,这已经在C中起了反作用。make需要生成一个特定于make的include文件,以表示C文件对其头文件的依赖关系,因此对后者的更改将导致在重新构建之前。但是,由于C文件本身没有被重新创建(只是重新构建),make常常需要将目标指定为. phony。幸运的是,GCC支持自动生成这些文件。
In Java, dependency can be circular, and there's no tool for auto-generating class dependencies in make
format. ant
's Depend
task can, instead, read the class file directly, determine which classes it imports, and delete the class file if any of them are out of date. Without this, any non-trivial dependency may result in you being forced to use repeated clean builds, removing any advantage of using a build tool.
在Java中,依赖关系可以是循环的,并且没有工具在make格式中自动生成类依赖关系。相反,ant的Depend任务可以直接读取类文件,确定它导入的类,并在任何类文件过时时删除类文件。如果没有这些,任何重要的依赖项都可能导致您*使用重复的干净构建,从而消除使用构建工具的任何优势。
Spaces in filenames
While neither Java nor C encourage using spaces in your source code filenames, in make
this can be problem even if the spaces are in the file path. Consider, for example, if your source code exists in C:\My Documents\My Code\program\src
. This would be enough to break make
. This is because make
treats filenames as strings. ant
treats paths as special objects.
虽然Java和C都不鼓励在源代码文件名中使用空格,但这样做可能会造成问题,即使空格位于文件路径中。考虑一下,例如,如果您的源代码存在于C:\我的文档\我的代码\程序\src中。这就足够打破常规了。这是因为将文件名作为字符串处理。ant将路径视为特殊对象。
Scanning files for build
make
requires explicitly setting which files are to be built for each target. ant
allows specifying a folder which is to be auto-scanned for source files. It may seem like a minor convenience, but consider that in Java each new class requires a new file. Adding files to the project can become a big hassle fast.
make需要显式地设置要为每个目标构建哪些文件。ant允许指定要自动扫描源文件的文件夹。这看起来似乎有点小方便,但请考虑在Java中,每个新类都需要一个新文件。向项目添加文件很快就会成为一个大麻烦。
And the biggest problem with make
:
最大的问题是
make is POSIX-dependent
Java's motto is "compile once run everywhere". But restricting that compilation to POSIX-based systems, in which Java support is actually the worst, is not the intention.
Java的座右铭是“编译一次,到处运行”。但是,将编译限制在基于posix的系统(其中Java支持实际上是最糟糕的)并不是初衷。
Build rules in make
are essentially small bash
scripts. Even though there is a port of make
to Windows, for it to work properly, it has to be bundled with a port of bash
, which includes a POSIX emulation layer for the file system.
make中的构建规则本质上是小型bash脚本。即使有一个到Windows的make端口,要让它正常工作,它也必须与bash的端口绑定,该端口包括文件系统的POSIX仿真层。
This comes in two varieties:
这有两种类型:
-
MSYS
which tries to limit the POSIX translation to file paths, and can therefore have unpleasant gotchas when running external tools not made especially for it.MSYS试图将POSIX转换限制为文件路径,因此在运行外部工具时,可能会遇到不愉快的问题。
-
cygwin
which provides a complete POSIX emulation. The resulting programs, however, tend to still rely on that emulation layer.cygwin提供一个完整的POSIX仿真。然而,生成的程序往往仍然依赖于仿真层。
For that reason, on Windows, the standard build tool isn't even make
at all, but rather MSBuild
, which is also an XML-based tool, closer in principle to ant
.
出于这个原因,在Windows上,标准的构建工具甚至根本就没有生成,而是MSBuild,它也是一种基于xml的工具,在原则上更接近ant。
By contrast, ant
is built in Java, can run everywhere, and contains internal tools, called "tasks", for manipulating files and executing commands in a platform-independent way. It's sufficiently versatile that you can actually have an easier time building a C program in Windows using ant
than using make
.
相比之下,ant是用Java构建的,可以在任何地方运行,并且包含内部工具,称为“任务”,用于以独立于平台的方式操作文件和执行命令。它的用途非常广泛,您可以在Windows中使用ant比使用make更容易地构建一个C程序。
And one last minor one:
最后一个小问题:
Even C programs don't use make natively
You may not initially notice this, but C programs generally aren't shipped with a Makefile
. They are shipped with a CMakeLists.txt
, or a bash
configuration script, which generates the actual Makefile
. By contrast, the source of a Java program built using ant
is shipped with an ant
script pre-built. A Makefile
is a product of other tools - That's how much make
is unsuitable to be a build tool on its own. ant
is standalone, and deals with everything you need for your Java build process, without any additional requirements or dependencies.
您可能最初没有注意到这一点,但是C程序通常不会附带Makefile。他们与顾客一起装运。txt,或bash配置脚本,生成实际的Makefile。相比之下,使用ant构建的Java程序的源代码是通过预先构建的ant脚本发送的。Makefile是其他工具的产物——这就是make本身不适合作为构建工具的原因。ant是独立的,并处理您的Java构建过程所需的一切,而不需要任何额外的需求或依赖。
When you run ant
on any platform, it Just Works(tm). You can't get that with make
. It's incredibly platform and configuration dependent.
当您在任何平台上运行ant时,它都会正常工作(tm)。你不能用make得到它。它非常依赖于平台和配置。
#13
1
One big reason is that both Ant and Maven (and most java targeted SCM, CI and IDE tools) are written in java by/for java developers. This makes it simpler to integrate into your development environment and allows other tools such as the IDE and CI servers to integrate portions of the ant/maven libraries within the build/deployment infrastructure.
一个重要的原因是Ant和Maven(以及大多数针对java的SCM、CI和IDE工具)都是java开发人员编写的。这使得集成到开发环境中更加简单,并允许其他工具(如IDE和CI服务器)在构建/部署基础结构中集成部分ant/maven库。
#14
1
Once upon a time I worked on a Java project that used gmake. My recollection is hazy but IIRC we had a hard time dealing with the package directory structure that javac expects. I also remember that building JAR files was a hassle unless you had something trivial.
曾几何时,我在一个使用gmake的Java项目上工作。我的记忆是模糊的,但是我们很难处理javac所期望的包目录结构。我还记得构建JAR文件是一件麻烦事,除非你有一些琐碎的事情。
#15
0
Ant and Maven approach the build dependency graph and the management of it from a more 'modern' view... But as Oscar says, they created their own problems while attempting to address the old problems with make.
Ant和Maven通过更“现代”的视角来处理构建依赖关系图和管理。但正如奥斯卡所说,他们在试图解决make的旧问题的同时,也制造了自己的问题。
#16
0
I've never used GNU Make for Java projects, but I used to use jmk. Sadly it hasn't been updated since 2002.
我从未在Java项目中使用GNU Make,但是我曾经使用jmk。遗憾的是,它自2002年以来就没有更新过。
It had some Java-specific functionality but was small enough to include in your source tarball without significantly increasing its size.
它有一些特定于java的功能,但是足够小,可以包含在源tarball中,而不会显著增加它的大小。
Nowadays I just assume any Java developer I share code with has Ant installed.
现在,我假设与我共享代码的任何Java开发人员都安装了Ant。
#17
0
ApacheAnt isn't anything like Make. Make is about describing dependencies between files, and how to build files. Ant is about dependencies between "tasks", and is really more of a way of gluing build scripts together.
ApacheAnt不像Make。Make是描述文件之间的依赖关系,以及如何构建文件。Ant是关于“任务”之间的依赖关系,实际上它更像是一种将构建脚本粘合在一起的方法。
it may helps you AntVsMake
它可能对你有所帮助