Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is no one using make for Java?

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.

Is there some fundamental flaw with make when used with Java? Is it just because Ant and Maven are written in Java?

like image 591
User1 Avatar asked Feb 05 '10 19:02

User1


People also ask

Is makefile used for java?

Makefile for Java Programs. To use this makefile to compile your java programs: create a file named 'makefile' in your project directory with the same content as this example starting from "makefile begins". modify the CLASSES macro so that it has the names of your .

What are make files?

The makefile is a text file that contains the recipe for building your program. It usually resides in the same directory as the sources, and it is usually called Makefile . Each one of these commands should be a separate rule in a makefile.


2 Answers

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.

With basic C, that typically "to convert a main.c file to a main.o file, run "cc main.c".

You can do that in java, but you quickly learn something.

Mostly that the javac compiler is slow to start up.

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.

Make also isn't very good at determining what files are out of date, at a collection level.

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.

That's why alternatives like Ant and Maven rose up.

like image 183
Will Hartung Avatar answered Nov 10 '22 14:11

Will Hartung


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.

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.

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.

like image 23
Greg Hewgill Avatar answered Nov 10 '22 15:11

Greg Hewgill