Ant vs Makefiles

Discussion in 'Java' started by Harris L, Nov 26, 2004.

  1. Harris L

    Harris L Guest

    Hi,

    I am working on a project that is written in Java but it's mainly used
    in Unix environments and uses Makefiles to build.

    I want to develop on this project in a Windows environment and I want
    to:

    ***Convert the Makefiles into Ant Build files***

    Please note that I am not particularly familiar with either (Makefile
    or Ant).

    If any of you has any suggestions, pointers or references of how to do
    this that it would be greatly appreciated.

    Regards,
    Harris
    Harris L, Nov 26, 2004
    #1
    1. Advertising

  2. Harris L

    Anzime Guest

    Harris L wrote:
    > Hi,
    >
    > I am working on a project that is written in Java but it's mainly used
    > in Unix environments and uses Makefiles to build.
    >
    > I want to develop on this project in a Windows environment and I want
    > to:
    >
    > ***Convert the Makefiles into Ant Build files***
    >
    > Please note that I am not particularly familiar with either (Makefile
    > or Ant).
    >
    > If any of you has any suggestions, pointers or references of how to do
    > this that it would be greatly appreciated.
    >
    > Regards,
    > Harris


    Figure out what the makefile(s) is/are doing, then do the same using
    Ant. You'll have to read the ant docs to figure out how to use Ant.

    http://ant.apache.org

    --
    Regards,
    Anzime
    Anzime, Nov 26, 2004
    #2
    1. Advertising

  3. Harris L

    Joe Guest

    In article <Y3Opd.147365$bk1.15841@fed1read05>,
    says...
    > Figure out what the makefile(s) is/are doing, then do the same using
    > Ant. You'll have to read the ant docs to figure out how to use Ant.
    >



    I laughed out loud when I read this.

    What Mr Obvious is trying to say is that make and ant take two different
    approaches. There isn't an automatic translator between the two (that I
    know of).
    Joe, Nov 26, 2004
    #3
  4. Harris L

    Ann Guest

    "Harris L" <> wrote in message
    news:...
    > Hi,
    >
    > I am working on a project that is written in Java but it's mainly used
    > in Unix environments and uses Makefiles to build.
    >
    > I want to develop on this project in a Windows environment and I want
    > to:
    >
    > ***Convert the Makefiles into Ant Build files***
    >
    > Please note that I am not particularly familiar with either (Makefile
    > or Ant).
    >
    > If any of you has any suggestions, pointers or references of how to do
    > this that it would be greatly appreciated.
    >
    > Regards,
    > Harris


    Is there a reason/justification to use Ant? Other than 'cuz' of course.
    Ann, Nov 27, 2004
    #4
  5. Harris L

    Sudsy Guest

    Ann wrote:
    > "Harris L" <> wrote in message

    <snip>
    >>Please note that I am not particularly familiar with either (Makefile
    >>or Ant).
    >>
    >>If any of you has any suggestions, pointers or references of how to do
    >>this that it would be greatly appreciated.
    >>
    >>Regards,
    >>Harris

    >
    >
    > Is there a reason/justification to use Ant? Other than 'cuz' of course.


    Make is a superb tool for building applications/executables in the
    structured programming, *NIX environment. It properly resolves
    dependencies and builds only what is needed.
    It doesn't do such a good job with Java, where compilation doesn't
    preclude cyclical dependencies. It doesn't incorporate the features
    to handle the situation. You can jury-rig something, with bailing
    wire and duct tape, but it's going to be fragile.
    Ant handles the situation with aplomb, although it is saddled with
    the usual criticisms (valid) about slow initial start-up.
    So it's not 'just becase'. Use make if your code is C or C++. Use
    ant if your code is Java.
    Every tool has its place; ever try to loosen a 1/2" nut with a
    screwdriver or needle nose pliers? ;-)

    --
    Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
    Sudsy, Nov 27, 2004
    #5
  6. Harris L

    Ann Guest

    "Sudsy" <> wrote in message
    news:...
    > Ann wrote:
    > > "Harris L" <> wrote in message

    > <snip>
    > >>Please note that I am not particularly familiar with either (Makefile
    > >>or Ant).
    > >>
    > >>If any of you has any suggestions, pointers or references of how to do
    > >>this that it would be greatly appreciated.
    > >>
    > >>Regards,
    > >>Harris

    > >
    > >
    > > Is there a reason/justification to use Ant? Other than 'cuz' of course.

    >
    > Make is a superb tool for building applications/executables in the
    > structured programming, *NIX environment. It properly resolves
    > dependencies and builds only what is needed.
    > It doesn't do such a good job with Java, where compilation doesn't
    > preclude cyclical dependencies. It doesn't incorporate the features
    > to handle the situation. You can jury-rig something, with bailing
    > wire and duct tape, but it's going to be fragile.
    > Ant handles the situation with aplomb, although it is saddled with
    > the usual criticisms (valid) about slow initial start-up.
    > So it's not 'just becase'. Use make if your code is C or C++. Use
    > ant if your code is Java.
    > Every tool has its place; ever try to loosen a 1/2" nut with a
    > screwdriver or needle nose pliers? ;-)
    >

    Great, then maybe you can suggest a solution for me since I am
    new to Ant. I have a file that contains mostly constants. When
    it changes there are a dozen other files that must be recompiled.
    TIA
    Ann
    Ann, Nov 27, 2004
    #6
  7. "Ann" <> wrote in message
    news:sx2qd.153907$HA.119962@attbi_s01...
    > Great, then maybe you can suggest a solution for me since I am
    > new to Ant. I have a file that contains mostly constants. When
    > it changes there are a dozen other files that must be recompiled.



    It's funny, but for all of its reputation as the premier build tool for
    Java, Ant doesn't do thorough dependency checking. It assumes that XXX.java
    is the only input to XXX.class. The only command-line tool I know of that
    does a better job is jikes, which can be used with or without make (see
    http://bekaffe.sourceforge.net/documentation/jikes/jikes.html#make).
    Mike Schilling, Nov 27, 2004
    #7
  8. Harris L

    Joe Guest

    In article <sx2qd.153907$HA.119962@attbi_s01>, lid
    says...
    > Great, then maybe you can suggest a solution for me since I am
    > new to Ant. I have a file that contains mostly constants. When
    > it changes there are a dozen other files that must be recompiled.
    > TIA
    > Ann
    >



    If your constants are changing, then they aren't really constant are
    they?
    Joe, Nov 27, 2004
    #8
  9. Anzime wrote:

    > ...
    >
    > Figure out what the makefile(s) is/are doing, then do the same using
    > Ant. You'll have to read the ant docs to figure out how to use Ant.
    >
    > http://ant.apache.org
    >


    Strangely enough. I find subtle wisdom in that answer, eventhough it might
    seem a bit obvious.

    If you have a Java project that uses make, then it is most likely written
    quite some time ago and/or it is written by someone with a C background and
    a limited Java understanding. Either case you would want to completely
    review your project's build process. Do not translate the make file(s)
    line-by-line into a ant file.

    As the poster wrote. You need to figure what the makefiles are doing (from a
    top-down perspective), and then do (approximately) same thing with ant. But
    be very critical of how the source code and built files are organised in the
    original make environment, very likely it will be done in a way that is
    uncommon and unconstructive in a Java environment.

    I have pasted in a build file from one of my own projects. As an example of
    some of the things you can very easily using ant. The build file compiles
    sources from the src directory into classes using a classpath with all jars
    in the lib directory, then packages the classes with ressources from res and
    metainformation from etc into a single jar file. There is an additional test
    target that runs a test class using the generated classpath.

    Also beware many deployment tasks such as servlet container control and file
    transfer can be automated using specialised ant tasks.

    -- Christian
    http://vredungmand.dk

    <project name="octopod" default="dist" basedir=".">
    <!-- set global properties for this build -->
    <property name="project" value="lightweight"/>
    <property name="src" value="src"/>
    <property name="build" value="classes"/>
    <property name="build.compiler" value="jikes"/>
    <property name="doc" value="javadoc"/>
    <property name="lib" value="lib"/>
    <property name="dist" value="."/>
    <property name="etc" value="etc"/>
    <property name="res" value="res"/>
    <property name="project-class-id" refid="project.class.id"/>

    <!-- throw everything inside lib in the classpath -->

    <path id="project.class.id">
    <pathelement path="${classpath}"/>
    <fileset dir="${lib}">
    <include name="**/*.jar"/>
    </fileset>
    </path>

    <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
    </target>

    <target name="compile" depends="init">
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}" nowarn="on">
    <classpath refid="project.class.id"/>
    </javac>
    </target>

    <target name="test" depends="dist">
    <exec executable="java">
    <arg line="-cp ${project}.jar:${project-class-id} test.Main"/>
    </exec>
    </target>

    <target name="dist" depends="compile">
    <mkdir dir="${dist}" />
    <jar manifest="etc/manifest.mf" jarfile="${project}.jar">
    <fileset dir="${build}"/>
    <fileset dir="${res}"/>
    </jar>
    </target>

    <target name="clean">
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${test}"/>
    </target>

    <target name="javadoc">
    <delete dir="${doc}"/>
    <mkdir dir="${doc}"/>
    <javadoc packagenames="*.*" sourcepath="${src}"
    excludepackagenames="test.*" defaultexcludes="yes"
    destdir="${doc}" author="true"
    version="true" use="true" windowtitle="Octopod">
    <doctitle><![CDATA[<h1>Octopod</h1>]]></doctitle>
    <bottom><![CDATA[<i>2004 by Christian Hvid.</i>]]></bottom>
    <link
    href="http://developer.java.sun.com/developer/products/xml/docs/api/"/>
    </javadoc>
    </target>
    </project>
    Christian Hvid, Nov 27, 2004
    #9
  10. Harris L

    Ann Guest

    "Joe" <> wrote in message
    news:...
    > In article <sx2qd.153907$HA.119962@attbi_s01>, lid
    > says...
    > > Great, then maybe you can suggest a solution for me since I am
    > > new to Ant. I have a file that contains mostly constants. When
    > > it changes there are a dozen other files that must be recompiled.
    > > TIA
    > > Ann
    > >

    >
    >
    > If your constants are changing, then they aren't really constant are
    > they?


    Just like Hubble's constant ;-)
    (What was originally thought to be a constant actually changes
    as the universe expands.)
    Ann, Nov 27, 2004
    #10
  11. Harris L

    Sudsy Guest

    Ann wrote:
    <snip>
    > Great, then maybe you can suggest a solution for me since I am
    > new to Ant. I have a file that contains mostly constants. When
    > it changes there are a dozen other files that must be recompiled.


    A bit of wading through the documentation provides the answer in the
    form of the dependset tag. Suppose file X.java depends on static
    variables in Y.java. To force both to be recompiled when Y.java
    changes, use the following:

    <dependset>
    <srcfilelist dir="." files="Y.java" />
    <targetfilelist dir="." files="Y.class,X.class" />
    </dependset>

    Please refer to the javadocs for the specifics.

    --
    Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
    Sudsy, Nov 27, 2004
    #11
  12. Harris L

    Ann Guest

    fantastic, tnx,
    ann


    "Sudsy" <> wrote in message
    news:...
    > Ann wrote:
    > <snip>
    > > Great, then maybe you can suggest a solution for me since I am
    > > new to Ant. I have a file that contains mostly constants. When
    > > it changes there are a dozen other files that must be recompiled.

    >
    > A bit of wading through the documentation provides the answer in the
    > form of the dependset tag. Suppose file X.java depends on static
    > variables in Y.java. To force both to be recompiled when Y.java
    > changes, use the following:
    >
    > <dependset>
    > <srcfilelist dir="." files="Y.java" />
    > <targetfilelist dir="." files="Y.class,X.class" />
    > </dependset>
    >
    > Please refer to the javadocs for the specifics.
    >
    > --
    > Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
    >
    Ann, Nov 27, 2004
    #12
  13. Harris L

    Juha Laiho Guest

    "Ann" <> said:
    >Great, then maybe you can suggest a solution for me since I am
    >new to Ant. I have a file that contains mostly constants. When
    >it changes there are a dozen other files that must be recompiled.


    Hmm.. that sounds like a combination of a property file and a class
    to me. So, if you have constant values, separate them into a property
    file that is read when the class is loaded (or an instance created,
    whichever suits better to the logic).

    Then have a separate class (without the external data), that just
    contains the dynamic behaviour you need - and have the dependent
    classes call that class to get the information they need. This should
    relieve you from recompiling just because a piece of "constant data"
    did change - instead just modify the data and repackage/redeploy the
    application.
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
    Juha Laiho, Nov 28, 2004
    #13
  14. Harris L

    Ann Guest

    "Juha Laiho" <> wrote in message
    news:coc7o8$qck$-int...
    > "Ann" <> said:
    > >Great, then maybe you can suggest a solution for me since I am
    > >new to Ant. I have a file that contains mostly constants. When
    > >it changes there are a dozen other files that must be recompiled.

    >
    > Hmm.. that sounds like a combination of a property file and a class
    > to me. So, if you have constant values, separate them into a property
    > file that is read when the class is loaded (or an instance created,
    > whichever suits better to the logic).
    >
    > Then have a separate class (without the external data), that just
    > contains the dynamic behaviour you need - and have the dependent
    > classes call that class to get the information they need. This should
    > relieve you from recompiling just because a piece of "constant data"
    > did change - instead just modify the data and repackage/redeploy the
    > application.
    > --

    Tnx for the idea. Unfortunately the guy I work with made a huge fuss
    about not reading any property (or other)files. And he wants all of the java
    files in a single directory. He took the 'package' statements
    out of some library files he wanted to use and moved them into the main
    directory.
    The <dependset> thing works though.
    Ann, Nov 28, 2004
    #14
  15. "Ann" <> wrote in message
    news:jFnqd.167634$R05.69144@attbi_s53...
    >
    > "Juha Laiho" <> wrote in message
    > news:coc7o8$qck$-int...
    >> "Ann" <> said:
    >> >Great, then maybe you can suggest a solution for me since I am
    >> >new to Ant. I have a file that contains mostly constants. When
    >> >it changes there are a dozen other files that must be recompiled.

    >>
    >> Hmm.. that sounds like a combination of a property file and a class
    >> to me. So, if you have constant values, separate them into a property
    >> file that is read when the class is loaded (or an instance created,
    >> whichever suits better to the logic).
    >>
    >> Then have a separate class (without the external data), that just
    >> contains the dynamic behaviour you need - and have the dependent
    >> classes call that class to get the information they need. This should
    >> relieve you from recompiling just because a piece of "constant data"
    >> did change - instead just modify the data and repackage/redeploy the
    >> application.
    >> --

    > Tnx for the idea. Unfortunately the guy I work with made a huge fuss
    > about not reading any property (or other)files. And he wants all of the
    > java
    > files in a single directory. He took the 'package' statements
    > out of some library files he wanted to use and moved them into the main
    > directory.


    He did what?

    Do this:

    First, ask him to post a question about whether this is the proper design to
    comp.lang.java.programmer.

    Next, buy a dustpan, so you have something to sweep up the ashes with.
    > The <dependset> thing works though.
    >
    >
    Mike Schilling, Nov 28, 2004
    #15
  16. On Sun, 28 Nov 2004 17:11:43 GMT, Ann wrote:

    > Unfortunately the guy I work with made a huge fuss
    > about not reading any property (or other)files. And he wants all of the java
    > files in a single directory. He took the 'package' statements
    > out of some library files he wanted to use and moved them into the main
    > directory.


    Packaged library classes to 'default' package?
    You have to *work* with this guy? Aaaaargh! :-(

    Tell him he's a bozo, as a special message from me.

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
    Andrew Thompson, Nov 28, 2004
    #16
  17. Harris L

    Ann Guest

    "Andrew Thompson" <> wrote in message
    news:...
    > On Sun, 28 Nov 2004 17:11:43 GMT, Ann wrote:
    >
    > > Unfortunately the guy I work with made a huge fuss
    > > about not reading any property (or other)files. And he wants all of the

    java
    > > files in a single directory. He took the 'package' statements
    > > out of some library files he wanted to use and moved them into the main
    > > directory.

    >
    > Packaged library classes to 'default' package?
    > You have to *work* with this guy? Aaaaargh! :-(
    >
    > Tell him he's a bozo, as a special message from me.
    >

    I'd love to. I continually pester him.
    Get this: he has all his files in C:\j2sdk1.4.2\bin
    because he couldn't get classpath to work and he
    wants to be able to do "javac *.java"
    He uses the 'it's my football' technique, so I can walk away.
    But it does give me the opportunity to write some swing code.
    Ann, Nov 28, 2004
    #17
  18. Harris L

    Sudsy Guest

    Ann wrote:
    > "Andrew Thompson" <> wrote in message

    <snip>
    >>Tell him he's a bozo, as a special message from me.
    >>

    >
    > I'd love to. I continually pester him.
    > Get this: he has all his files in C:\j2sdk1.4.2\bin
    > because he couldn't get classpath to work and he
    > wants to be able to do "javac *.java"
    > He uses the 'it's my football' technique, so I can walk away.
    > But it does give me the opportunity to write some swing code.

    <snip>

    You have to appreciate Andrew's no-nonsense approach. But now it
    makes more sense that you're "trying to do the right thing" by
    migrating to Ant. Seriously, "javac *.java"?! Ye gods!

    ps. Glad I was able to help you with the dependset tag. I didn't
    know about it either until I began my excavation, but I
    figured that the capability HAD to exist in some shape or
    form. [I should charge for my research... ;-) ]

    --
    Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
    Sudsy, Nov 29, 2004
    #18
  19. Harris L

    Ann Guest

    "Sudsy" <> wrote in message
    news:...
    > Ann wrote:
    > > "Andrew Thompson" <> wrote in message

    > <snip>
    > >>Tell him he's a bozo, as a special message from me.
    > >>

    > >
    > > I'd love to. I continually pester him.
    > > Get this: he has all his files in C:\j2sdk1.4.2\bin
    > > because he couldn't get classpath to work and he
    > > wants to be able to do "javac *.java"
    > > He uses the 'it's my football' technique, so I can walk away.
    > > But it does give me the opportunity to write some swing code.

    > <snip>
    >
    > You have to appreciate Andrew's no-nonsense approach. But now it
    > makes more sense that you're "trying to do the right thing" by
    > migrating to Ant. Seriously, "javac *.java"?! Ye gods!
    >
    > ps. Glad I was able to help you with the dependset tag. I didn't
    > know about it either until I began my excavation, but I
    > figured that the capability HAD to exist in some shape or
    > form. [I should charge for my research... ;-) ]


    I really appreciate your looking it up and testing it out.
    Since my 'buddy' is in a different city I feel it safe to put
    my version of the source in a reasonable structure and to use ant
    which is very convenient.
    Ann, Nov 29, 2004
    #19
  20. Harris L

    bugbear Guest

    Mike Schilling wrote:
    > "Ann" <> wrote in message
    > news:sx2qd.153907$HA.119962@attbi_s01...
    >
    >>Great, then maybe you can suggest a solution for me since I am
    >>new to Ant. I have a file that contains mostly constants. When
    >>it changes there are a dozen other files that must be recompiled.

    >
    >
    >
    > It's funny, but for all of its reputation as the premier build tool for
    > Java, Ant doesn't do thorough dependency checking.


    It's not funny ; it's very annoying.

    Whilst make is built around the concept of file-dependancies,
    and has powerful tools for expressing these in general ways
    (e.g. pattern dependancies), and is built around
    target dependancies. Many of the commands in Ant
    implement their own file dependancy functionality
    (nice code architecture, I don't think).

    There is a desperate kludge within ant in the "dependset"
    task, but using it is verbose and ugly.

    I like the platform portability of Ant, and the ability
    to add (java implemented) extensions, but I'd have strongly
    preferred to have retained the elegant dependancy model
    of make.

    Life might have been so different if Ant's author
    had found a decent text editor. One of the prime motivations
    seems to have been avoiding the use of tab's in the control
    file!

    BugBear
    bugbear, Nov 29, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sasquatch

    Makefiles for JAVA

    sasquatch, Nov 8, 2003, in forum: Java
    Replies:
    5
    Views:
    735
    Dale King
    Nov 12, 2003
  2. dharmesh Gupta

    Making of Makefiles

    dharmesh Gupta, Aug 26, 2003, in forum: C++
    Replies:
    2
    Views:
    332
    Kevin Goodsell
    Aug 26, 2003
  3. Janne Naukkarinen
    Replies:
    1
    Views:
    364
    Jack Klein
    Jan 15, 2004
  4. db
    Replies:
    2
    Views:
    426
  5. Max

    Help on makefiles

    Max, Sep 26, 2004, in forum: C++
    Replies:
    12
    Views:
    1,939
    Phlip
    Sep 27, 2004
Loading...

Share This Page