It's not a secret anymore!
The moose likes Ant, Maven and Other Build Tools and the fly likes Opinion on this build.xml file I wrote Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Reply Bookmark "Opinion on this build.xml file I wrote" Watch "Opinion on this build.xml file I wrote" New topic
Author

Opinion on this build.xml file I wrote

v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223
project name="Guest Book" default="build" basedir=".">

<target name="build" >

<javac srcdir="C:\apache-tomcat-6.0.10\webapps\Guest Book\WEB-INF\classes"
destdir="C:\apache-tomcat-6.0.10\webapps\Guest Book\WEB-INF\classes"
classpath="C:\apache-tomcat-6.0.10\lib\servlet-api.jar" debug="true" includes="**/*.java"/>
</target>

</project>

What do you all think of this? Please suggest better ways of writing the same.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35253
    
    7
How about



You could even keep the tomcatDir and servletLib properties in a global property file, since they are likely to be used in other build files as well. That way you only need to change them in a single location if necessary.
[ May 16, 2007: Message edited by: Ulf Dittmer ]

Android appsImageJ pluginsJava web charts
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

1. I prefer to declare paths in property tags.
For example , one for the path to the root of the application (C:\apache-tomcat-6.0.10\webapps\Guest Book), one for the source (reusing the previous property), one for the destination, one for external libraries.
<property name="app.root" value="C:\apache-tomcat-6.0.10\webapps\Guest Book" />
<property name="app.src" value="..." />
<property name="app.classes" value="${app.root}\WEB-INF\classes" />

2. It's not an Ant related, but I would not put source files in the classes directory


[My Blog]
All roads lead to JavaRanch
v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223

<property name="servletLib" value="${tomcatDir}\lib\servlet-api.jar">

Can I use this like :
<property name="servletLib" value="${tomcatDir}\lib\" includes ="*.jar"> ???

Like, I am thinking if there is a situation where multiple jar files need to be used?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35253
    
    7
I think this should cover all the bases:

[ May 16, 2007: Message edited by: Ulf Dittmer ]
v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223
<property name="tomcatDir" value="C:\apache-tomcat-6.0.10\">

<property name="servletLib" value="${tomcatDir}\lib\servlet-api.jar">

<property name="webAppDir" value="${tomcatDir}\webapps\Guest Book">

<property name="classDir" value="${webAppDir}\WEB-INF\classes">

<path id="class.path">
<fileset dir="${webAppDir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${servletLib}" />
</path>


I am thinking, why do we need the path element when we already have specified all the jar files in the fileset dir?
Using servletLib, we are still pointed to servlet-api.jar right? or is that how it is done, we point to all the jar files we need to add one by one and those will be the path elements??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35253
    
    7
A path can contain any number of filesets and pathelements, so yes, this is necessary. These concepts are explained in detail with many examples in the Ant manual.
v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223
Yes, I got it, thank you so much for clearing all my doubts!
Padma priya Gururajan
Ranch Hand

Joined: Oct 05, 2006
Posts: 411
Hi Ulf,
Where is the Ant Manual available?
With regards,
Padma priya N.G.


Padma priya N.G.
Be the change you want to be - Mahatma Gandhi
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Opinion on this build.xml file I wrote
 
Similar Threads
Exception in thread "main" java.lang.NoClassDefFoundErro
Deployment problem
Deployment problem
HTTP Status 404 - /Ch03/
How to automate deployment of war in Tomcat through Ant