Tutorial :Which version of Make to use for Java?


I have make (Windows SDK), nmake (Visual Studio) and make (CodeGear)

Which version of make do I use to compile Java apps? Where do I get this "make" from? I downloaded the JDK and there is no make. I searched around for something to compile a Java makefile.

What do you use, if you have a MAKEFILE and some *.java files?


Java projects rarely use make and makefiles. In fact, I've only ever seen this used once in practice however and that was 13 years ago, predating Java build tools. Instead Java projects use one of the two leading build tools.

Based on your question I'm going to assume you have no particular reason to use make (in that you're not trying to compile an existing project that only has a Makefile).


Ant is an XML-based scripting build tool that bears a little (but not a lot) similarity to a makefile in concept. An Ant build script will define a number of tasks. Those tasks will depend on other tasks. The tasks can include compiling Java source files, building jars and anything you like really.

Ant is very flexible but also you end up writing a bunch of boilerplate over and over (between projects). No two moderately complex Ant projects are the same and dependencies can become a huge problem. By "dependencies" I'm not talking about source dependencies but dependencies on third-party libraries. Ant has another tool called Ivy for managing dependencies.


Maven is the other common build tool. Maven differs greatly from Ant in that Maven defines project types (archetypes) such as a Web application. When you choose one (or more) archetype for your project, it mandates a directory structure that is quite deep. For example:

project-name  +- src/     +- main/        +- java/           +- com/example/project-name/              +- Java source files     +- test/        +- tends to mirror above  +- target/     +- classes/        +- com/example/project-name/           +- Java class files     +- test-classes/        +- tends to mirror above  ...etc...  

Now some people don't like this, in part because some people just don't like being told what to do (imho) but also for things like legacy reasons and other factors. Personally I consider it a good thing because once you're familiar with any Maven Web application project, you can go to any other Maven Web application project and find your way around.

Maven will also give you lots of standard commands to run, such as compile, test, install, etc.

Maven is also useful for dependencies on third-party libraries. You declare these in your Maven project file and they are retrieved from repositories on the internet (and cached locally unless you set it up otherwise).

So my advice is use one of these two. You may be used to Makefiles if you come from a C/C++ background but it isn't really the Java way. Like I said, you may have reason to use make with Java such as an existing project but for any new project you should absolutely use Ant or Maven instead, in my opinion.


Use any version that processes your makefile. Make doesn't do any compilation, it's just a scripting system designed with building software in mind. It's just going to delegate to javac or something else for compiling your Java files.

I would try all three already on your system.


There are two answers.

A1: If you want to use the MAKEFILE, you need to look at the build documentation that comes with the software to find out which version of make to use. If there is no build documentation relevant to your platform, look at the documentation for the platform the software was originally implemented on. There have been many different versions of Make over the years, and each version has its own quirks.

The other problem that you might encounter with the MAKEFILE is that makefiles are not portable. There are typically all sorts of platform dependencies in the rules that get run; e.g. command names, command paths, and so on. If you are trying to build on a different platform, these issues may require you to hack the MAKEFILE. (Aside: in the C / C++ world, there is a labyrinthine suite of GNU tools called automake / autoconf that is designed to address this problem. But by the sounds of it, you just have a vanilla makefile.)

In summary, if you want to stick with make, do what the build documentation says and in the absence of any relevant build documentation, just try any version of make and see what happens. And be prepared to learn "make-ese" and hack makefiles if there are platform related issues.

A2: IMO, a better alternative to this would be to ditch the existing MAKEFILE and create your own build file using either Ant or Maven.


If you want an executable JAR, don't use the makefile, just follow these command prompts:

javac DiveLog.java  jar cvfm yourjarname.jar manifest allyourcompiledclasses.class  

And to run the jar from console, you type:

java -jar yourjarname.jar  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »