Hello,
I have a question about using make as the build-utilitiy for Java
programs. Please point me to a more appropriate news group if this is
not the group to discuss this.
Here is the context of my question:
------------------------------------------
A 'Node' contains NetworkPackets. NetworkPackets have a source Node.
My makefile captures this as:
...
Node.class: Node.java NetworkPacket.class
javac Node.java
NetworkPacket.class: NetworkPacket.java Node.class
javac NetworkPacket.java
...
First issue:
------------
With this, make discovers a cyclic dependency and drops it. I am sure
that per the design of make, this is expected behavior. The question
is, how should I represent the dependency in my program in a makefile?
Second issue:
-------------
I believe make will not have problems of this kind in the context of C/
C++ programs. Because of a clear seperation of declarations in a
header file and definitions in object files, the dependencies will
form 'trees' instead of 'cycles' as in the makefile snipped above. Is
makefile not the appropriate (or the best) tool to capture
dependencies in Java programs where we don't have a seperate header
and source files? My experience with make is limited to relatively
uncomplicated scenario and I would like to have the opinion of more
knowledgeable people on this point.
Regards
vkj
Daniel Dyer - 02 Jun 2007 23:58 GMT
> Hello,
>
> I have a question about using make as the build-utilitiy for Java
> programs. Please point me to a more appropriate news group if this is
> not the group to discuss this.
The obvious first question is why make and not Ant (http://ant.apache.org)?
> Here is the context of my question:
> ------------------------------------------
[quoted text clipped - 14 lines]
> that per the design of make, this is expected behavior. The question
> is, how should I represent the dependency in my program in a makefile?
Generally you would not compile individual source files. You should
compile both files at the same time because javac cannot resolve the
dependency otherwise:
javac Node.java NetworkPacket.java
Or
javac *.java
> Second issue:
> -------------
[quoted text clipped - 7 lines]
> uncomplicated scenario and I would like to have the opinion of more
> knowledgeable people on this point.
Use Ant unless you have a compelling reason not to.
Dan.

Signature
Daniel Dyer
http//www.uncommons.org
Arne Vajhøj - 03 Jun 2007 00:00 GMT
> I have a question about using make as the build-utilitiy for Java
> programs. Please point me to a more appropriate news group if this is
[quoted text clipped - 30 lines]
> uncomplicated scenario and I would like to have the opinion of more
> knowledgeable people on this point.
1)
I would suggest you try compiling all the java files in a dir with
one command:
javac *.java
2)
ant (http://ant.apache.org/) is a much better build tool than
make for Java.
Arne
Mike Schilling - 03 Jun 2007 05:07 GMT
> Hello,
>
> I have a question about using make as the build-utilitiy for Java
As others have pointerd out, it's a bad idea. Make's notion of one file
depending on another works badly in Java, where dependencies are complex,
difficult to derive, and often circular. As a result, Ant, which is the
most common build tool for Java projects, doesn't even try to process
dependencies correctly, but mostly works well enough without them.
veegnu@gmail.com - 03 Jun 2007 16:09 GMT
Daniel, Arne and Mike,
Thanks a lot for your kind attention and responses to my question. I
will move to Ant.
I knew that Ant is a widely used tool for building Java. But I thought
make was good enough for me and perhaps Ant provides sophistication
that I don't require for my project. Hence I was reluctant to change
so far. But now I realize the the makefiles' mode of capturing
dependencies is inadequate for Java (and my scenario) and make is not
the right tool.
Thanks again.
Regards
vkj