You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by James Javaman <ja...@gmail.com> on 2007/03/14 20:34:40 UTC

Example of a build.xml File for Tomcat ?

Hello,

I am trying to setup a build.xml file for a servlet.  I am using the
following 2 URL's as references:

http://tomcat.apache.org/tomcat-5.0-doc/manager-howto.html#Executing%20Manager%20Commands%20With%20Ant

http://www.onjava.com/onjava/2003/01/08/examples/build.xml.html


So my problem is I don't understand how day-to-day development would work
using this build.xml file.  For example, let's say I change some code that
will run on the servlet in a file called: MyServlet.java.
What series of ant commands would I run to reflect the change? Would it be:
ant undeploy
ant deploy
ant gui

I'm just asking because it seems like 'ant undeploy' and 'ant deploy' are
time-consuming to run if all I'm changing is one file.  I kind of confused
on how 'ant reload' is supposed to be used in the context of these files.  I
guess for 'ant reload' I would have to manually copy the output of javac to
the tomcat folder?  Does anyone have a more elegant build.xml file (or have
a suggestion for creating one.)

Thank you very much.  A solution to this problem will no doubt save me a lot
of development time.

Re: Example of a build.xml File for Tomcat ?

Posted by Daniel Gresh <dg...@lle.rochester.edu>.
james.javaman wrote:
> Hi Dan,
>
> Sorry if I’m being dense here, but how does the newly compiled code get into
> $CATALINA_HOME/webapps/myWebApp?
>
> I don’t see the part in your build.xml where the new changes (newly compiled
> changes) make it to the Tomcat directory.  
>
> According to your response, ${build} can point anywhere.  I mean, lets say
> ${build} points to: C:\temp\nowhere_of_significance.  Wouldn’t this mess up
> a reload? The only parameters I see in a reload are a username, password, a
> manager url and path of the tomcat web app.  Won’t this just reload the same
> thing (without our new change.)  Is there something happening "under the
> hood" I just can't see here where the compiled code magically gets put into
> the Tomcat directory?
>
> Thanks for your patience.  
>
>   
>
>   


Yes ${build} can point to anywhere. I have ${build} in my build.xml file 
set to $CATALINA_HOME/webapps/myWebApp/WEB-INF/classes, so the newly 
compiled code simply goes to that directory.

Therefore, you specify ${build} to be where you want your compiled code 
to go in your webapp (most likely in the path I just showed). There is 
nothing else to it; the code gets compiled to your webapp directory, 
then you reload the webapp. Reload will not occur until your code is 
done compiling, as there is a depends parameter for the reload target.

The reason you can call

ant reload

without calling

ant javac

is because reload depends on javac in the example I provided; it will 
not happen unless javac happens. Therefore, calling

ant reload

will also cause the javac command to execute.

Dan

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Example of a build.xml File for Tomcat ?

Posted by "james.javaman" <ja...@gmail.com>.
Hi Dan,

Sorry if I’m being dense here, but how does the newly compiled code get into
$CATALINA_HOME/webapps/myWebApp?

I don’t see the part in your build.xml where the new changes (newly compiled
changes) make it to the Tomcat directory.  

According to your response, ${build} can point anywhere.  I mean, lets say
${build} points to: C:\temp\nowhere_of_significance.  Wouldn’t this mess up
a reload? The only parameters I see in a reload are a username, password, a
manager url and path of the tomcat web app.  Won’t this just reload the same
thing (without our new change.)  Is there something happening "under the
hood" I just can't see here where the compiled code magically gets put into
the Tomcat directory?

Thanks for your patience.  





Daniel Gresh wrote:
> 
> james.javaman wrote:
>> Hi Dan,
>>
>> Thanks for your response.  Let me just make sure I heard you right:
>>
>> So I have a javac target in my build.xml file.  It simply compiles code
>> in
>> ${source} and puts it in {$build}.  You are suggesting that I point
>> {$build}
>> to the Tomcat directory?
>>
>> For example, since I’m on Windows, {$build} might be:
>> C:\Program Files\Apache Software Foundation\Tomcat
>> 6.0\webapps\myWebApplication\WEB-INF\classes
>>
>> So lets say I’ve changed some of my servlet code.  Could I then just do
>> this
>> to see it reflected: ?
>>
>> ant javac
>> ant reload
>> ant gui
>>
>>
>> Finally, is this the “official” (or good) way to do this? In other words,
>> this isn’t a “hack” or anything?  
>>
>>   
>>
>>   
> 
> 
> No you can keep ${build} where it is, as the javac command does not
> matter.
> 
> ant reload, if i recall the technical definition correctly, reloads the 
> context path of the web application. Therefore, rather than undeploying 
> your webapp and deploying it again to see the changes reflected when you 
> navigate to your webapp, you can call "ant reload" to reload the webapp 
> in Tomcat (yes I know it's not good practice to use the word you're 
> defining in the definition, but I don't know how else to put it). This 
> will "reflect" the changes.
> 
> This is certainly not a "hack", it's just a custom Ant task that you can 
> use with Tomcat, such as ant stop, ant start, ant deploy, etc.
> 
> I have a build.xml file I'm using for my webapp that uses reload. I have 
> it set up so if the compilation of my .java files is successful, it will 
> reload the webapp so I don't have to do it manually. Here is what the 
> relevant part of my build.xml file looks like:
> 
> <!-- Compile the .java files in the src directory and output to the 
> build directory -->
>     <target name="compile" depends="init">
>         <!-- Compile the java code -->
>         <javac srcdir="${src}" destdir="${build}" />
>     </target>
> 
>     <!-- Reload the web application in Apache Tomcat to process changes
> -->
>     <target name="reload" depends="compile" description="Reload web 
> application">
>         <reload url="${url}" username="${username}" 
> password="${password}" path="${path}" />
>     </target>
> 
> Where ${url} is the URL of my manager webapp, ${username} and 
> ${password} are the username and password for my manager webapp, and 
> ${path} is the path of the webapp I am reloading 
> ($CATALINA_HOME/webapps/myWebApp).
> 
> You can cause it to reload by typing:
> 
> ant reload
> 
> from the command line;
> 
> ant javac
> 
> is not needed.
> 
> Dan
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Example-of-a-build.xml-File-for-Tomcat---tf3404338.html#a9483268
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Example of a build.xml File for Tomcat ?

Posted by Daniel Gresh <dg...@lle.rochester.edu>.
james.javaman wrote:
> Hi Dan,
>
> Thanks for your response.  Let me just make sure I heard you right:
>
> So I have a javac target in my build.xml file.  It simply compiles code in
> ${source} and puts it in {$build}.  You are suggesting that I point {$build}
> to the Tomcat directory?
>
> For example, since I’m on Windows, {$build} might be:
> C:\Program Files\Apache Software Foundation\Tomcat
> 6.0\webapps\myWebApplication\WEB-INF\classes
>
> So lets say I’ve changed some of my servlet code.  Could I then just do this
> to see it reflected: ?
>
> ant javac
> ant reload
> ant gui
>
>
> Finally, is this the “official” (or good) way to do this? In other words,
> this isn’t a “hack” or anything?  
>
>   
>
>   


No you can keep ${build} where it is, as the javac command does not matter.

ant reload, if i recall the technical definition correctly, reloads the 
context path of the web application. Therefore, rather than undeploying 
your webapp and deploying it again to see the changes reflected when you 
navigate to your webapp, you can call "ant reload" to reload the webapp 
in Tomcat (yes I know it's not good practice to use the word you're 
defining in the definition, but I don't know how else to put it). This 
will "reflect" the changes.

This is certainly not a "hack", it's just a custom Ant task that you can 
use with Tomcat, such as ant stop, ant start, ant deploy, etc.

I have a build.xml file I'm using for my webapp that uses reload. I have 
it set up so if the compilation of my .java files is successful, it will 
reload the webapp so I don't have to do it manually. Here is what the 
relevant part of my build.xml file looks like:

<!-- Compile the .java files in the src directory and output to the 
build directory -->
    <target name="compile" depends="init">
        <!-- Compile the java code -->
        <javac srcdir="${src}" destdir="${build}" />
    </target>

    <!-- Reload the web application in Apache Tomcat to process changes -->
    <target name="reload" depends="compile" description="Reload web 
application">
        <reload url="${url}" username="${username}" 
password="${password}" path="${path}" />
    </target>

Where ${url} is the URL of my manager webapp, ${username} and 
${password} are the username and password for my manager webapp, and 
${path} is the path of the webapp I am reloading 
($CATALINA_HOME/webapps/myWebApp).

You can cause it to reload by typing:

ant reload

from the command line;

ant javac

is not needed.

Dan

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Example of a build.xml File for Tomcat ?

Posted by "james.javaman" <ja...@gmail.com>.
Hi Dan,

Thanks for your response.  Let me just make sure I heard you right:

So I have a javac target in my build.xml file.  It simply compiles code in
${source} and puts it in {$build}.  You are suggesting that I point {$build}
to the Tomcat directory?

For example, since I’m on Windows, {$build} might be:
C:\Program Files\Apache Software Foundation\Tomcat
6.0\webapps\myWebApplication\WEB-INF\classes

So lets say I’ve changed some of my servlet code.  Could I then just do this
to see it reflected: ?

ant javac
ant reload
ant gui


Finally, is this the “official” (or good) way to do this? In other words,
this isn’t a “hack” or anything?  




Daniel Gresh wrote:
> 
> James Javaman wrote:
>> Hello,
>>
>> I am trying to setup a build.xml file for a servlet.  I am using the
>> following 2 URL's as references:
>>
>> http://tomcat.apache.org/tomcat-5.0-doc/manager-howto.html#Executing%20Manager%20Commands%20With%20Ant 
>>
>>
>> http://www.onjava.com/onjava/2003/01/08/examples/build.xml.html
>>
>>
>> So my problem is I don't understand how day-to-day development would work
>> using this build.xml file.  For example, let's say I change some code 
>> that
>> will run on the servlet in a file called: MyServlet.java.
>> What series of ant commands would I run to reflect the change? Would 
>> it be:
>> ant undeploy
>> ant deploy
>> ant gui
>>
>> I'm just asking because it seems like 'ant undeploy' and 'ant deploy' are
>> time-consuming to run if all I'm changing is one file.  I kind of 
>> confused
>> on how 'ant reload' is supposed to be used in the context of these 
>> files.  I
>> guess for 'ant reload' I would have to manually copy the output of 
>> javac to
>> the tomcat folder?  Does anyone have a more elegant build.xml file (or 
>> have
>> a suggestion for creating one.)
>>
>> Thank you very much.  A solution to this problem will no doubt save me 
>> a lot
>> of development time.
>>
> ant reload simply reloads a web application. Therefore, if you update 
> MyFile.java and compile it to 
> $CATALINA_HOME/webapps/myWebApp/WEB-INF/classes/MyFile.class, you can 
> call ant reload on that specific web application to reload the web 
> application so your changes take effect.
> 
> Dan
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Example-of-a-build.xml-File-for-Tomcat---tf3404338.html#a9482168
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Example of a build.xml File for Tomcat ?

Posted by Daniel Gresh <dg...@lle.rochester.edu>.
James Javaman wrote:
> Hello,
>
> I am trying to setup a build.xml file for a servlet.  I am using the
> following 2 URL's as references:
>
> http://tomcat.apache.org/tomcat-5.0-doc/manager-howto.html#Executing%20Manager%20Commands%20With%20Ant 
>
>
> http://www.onjava.com/onjava/2003/01/08/examples/build.xml.html
>
>
> So my problem is I don't understand how day-to-day development would work
> using this build.xml file.  For example, let's say I change some code 
> that
> will run on the servlet in a file called: MyServlet.java.
> What series of ant commands would I run to reflect the change? Would 
> it be:
> ant undeploy
> ant deploy
> ant gui
>
> I'm just asking because it seems like 'ant undeploy' and 'ant deploy' are
> time-consuming to run if all I'm changing is one file.  I kind of 
> confused
> on how 'ant reload' is supposed to be used in the context of these 
> files.  I
> guess for 'ant reload' I would have to manually copy the output of 
> javac to
> the tomcat folder?  Does anyone have a more elegant build.xml file (or 
> have
> a suggestion for creating one.)
>
> Thank you very much.  A solution to this problem will no doubt save me 
> a lot
> of development time.
>
ant reload simply reloads a web application. Therefore, if you update 
MyFile.java and compile it to 
$CATALINA_HOME/webapps/myWebApp/WEB-INF/classes/MyFile.class, you can 
call ant reload on that specific web application to reload the web 
application so your changes take effect.

Dan

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org