Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ANT Target/Scripts

Options
  • 10-08-2009 3:59pm
    #1
    Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭


    Quick question.. not the best of understanding with this so trying to get my head around the whole ANT concept! With an ANT Target, what are considered global property decelerations and resource collection decelerations?

    From looking at the Apache guide on ANT, I see the various ways of declaring properties but what I cant get my head around is what would be considered properties from a target?


Comments

  • Moderators, Technology & Internet Moderators Posts: 1,335 Mod ✭✭✭✭croo


    I've sat looking at this for a few minutes and I have to say ... I'm not even sure what the question is! :)
    Did you really mean a "decelerations"?
    I'm thinking, "maybe it's declaration... but he type it twice the same!?" :)
    But I see 17 others looked an didn't comment so perhaps you could rephrase the question?


  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    Perhaps not the best way of explaining so hopefully this will make it a tad clearer. Its just revision for an exam covering ANT/Hibernation/Spring. :)

    An ant target excerpt was given and the question asked was "Write an appropriate set of global properly declarations and resource collection declarations for the excerpt". Once done, you were asked to re-write the first javac task using the declarations from above.

    From looking at the Apache guide on ANT, I see the various methods of declaring properties but what I cant get my head around is what would be considered properties from a target? The sample code I have seems to have a build properties file, but I don't think thats what is being looked for here.


  • Registered Users Posts: 1,916 ✭✭✭ronivek


    An example to illustrate your question might be appropriate here; I'm not entirely sure if I'm understanding you correctly...

    A property is simply a value that is set once and from that point on cannot be changed.

    Properties are effectively global constants if it helps to think of them that way; so in general you would declare them outside any targets using whatever method is easier; i.e. importing from a properties file or declaring each property within the Ant XML.

    Properties defined within targets and tasks are only set once that target/task is called from what I remember; but there is no notion of local scope with Ant properties if I recall correctly; maybe someone else can confirm.

    So in terms of your exam question any properties you set outside the target will be visible by that target; if that's what you were getting at.


  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    Seems to confirm my thinking but I wasnt sure exactly what is defined as a property.

    This is the code:-
    <target name="compile" depends="cleans">
    <javac destdir="bin\classes" srcdir="src\java">
    <classpath>
    <path element location="C:\common\lib\hibernate.jar"/>
    <path element location="C:\common\lib\spring.jar"/>
    </classpath>
    <include name="service\**"/>
    </javac>
    <javac destdir="bin\classes" srcdir="src\java">
    <classpath>
    <path element location="C:\common\lib\hibernate.jar"/>
    <path element location="C:\common\lib\spring.jar"/>
    <path element location="C:\common\lib\junit.jar"/>
    </classpath>
    <include name="service\**"/>
    </javac>
    <mkdir dir="test\report\xml" />
    <junit printsummary="true">
    <formatter type="xml">
    <batchtest todir="test\report\xml">
    <fileset dir="bin\classes">
    <include name="**\*Test*.class"/>
    </fileset>
    </batchtest>
    <classpath>
    <path element location="C:\common\lib\hibernate.jar"/>
    <path element location="C:\common\lib\spring.jar"/>
    <path element location="C:\common\lib\junit.jar"/>
    <path element location="bin\classes"/>
    </classpath>
    </junit>
    </target>
    


  • Registered Users Posts: 1,916 ✭✭✭ronivek


    Sully wrote: »
    Seems to confirm my thinking but I wasnt sure exactly what is defined as a property.

    This is the code:-

    ....

    Is this XML you've taken from an exam question or have you come up with it yourself?

    An example of adding properties here is below. It's by no means perfect and filesets could be used to extract for example the hibernate and spring JARs.



    [PHP]
    <property name="xmlReportDir" location="test\report\xml"/>
    <property name="javaDestDir" location="bin\classes"/>
    <property name="javaSrcDir" location="src\java"/>
    <property name="libDir" value="C:\common\lib"/>

    <target name="compile" depends="cleans">
    <javac destdir="${javaDestDir}" srcdir="${javaSrcDir}">
    <classpath>
    <path element location="${libDir}\hibernate.jar"/>
    <path element location="${libDir}\spring.jar"/>
    </classpath>
    <include name="service\**"/>
    </javac>

    <javac destdir="${javaDestDir}" srcdir="${javaSrcDir}">
    <classpath>
    <path element location="${libDir}\hibernate.jar"/>
    <path element location="${libDir}\spring.jar"/>
    <path element location="${libDir}\junit.jar"/>
    </classpath>
    <include name="service\**"/>
    </javac>

    <mkdir dir="${xmlReportDir}" />
    <junit printsummary="true">
    <formatter type="xml"/>
    <batchtest todir="${xmlReportDir}">
    <fileset dir="${javaDestDir}">
    <include name="**\*Test*.class"/>
    </fileset>
    </batchtest>
    <classpath>
    <path element location="${libDir}\hibernate.jar"/>
    <path element location="${libDir}\spring.jar"/>
    <path element location="${libDir}\junit.jar"/>
    <path element location="${javaDestDir}"/>
    </classpath>
    </junit>
    </target>
    [/PHP]


  • Advertisement
  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    Thanks for that. It makes sense, but then when asked to use those decelerations in the first javac element - have we not already done that by answering the first part?

    Or would I be correct in assuming the first four lines are the property decelerations and then you changed the rest of the XML file so that they are used?


  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    *bump* :)


  • Registered Users Posts: 1,916 ✭✭✭ronivek


    Sully wrote: »
    Or would I be correct in assuming the first four lines are the property decelerations and then you changed the rest of the XML file so that they are used?

    You would be correct aye. It's the same principle used in programming and scripting; you're declaring things that remain constant in a single location to make your scripts/files as easy to maintain and alter as possible.


  • Moderators, Education Moderators, Technology & Internet Moderators, Regional South East Moderators Posts: 24,056 Mod ✭✭✭✭Sully


    ronivek wrote: »
    You would be correct aye. It's the same principle used in programming and scripting; you're declaring things that remain constant in a single location to make your scripts/files as easy to maintain and alter as possible.

    Ah very good, thanks for that. Are the include statements the same principal used in scripting languages such as php? In the above example;
    <include name="service\**"/>
    

    Including every single file in the service directory, for the compiling of that java source tree? The significance is that it makes life easier writing statements to pull each and every file, while the above (with the use of wildcards) will allow to pull them in at once and where relevant? I have seen them in use in fileset element tags also, but I guess that's just specifying the directory the include statement is for?


Advertisement