You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Rob Wilson <ne...@gmail.com> on 2007/10/30 22:14:56 UTC

deploy task to Tomcat partially works

Hi All,

I have written my first Ant script from scratch, using google and the
O'reilly definitive guide.  I'm mostly happy with what I have ended up with,
however when I try to use the Tomcat DeployTask my application is not
deployed as expected.

If I manually copy my war file to the webapps directory everything is fine,
so I really would like to understand how to use ant to deploy using the
Tomcat task (rather than copying directly to the webapp folder - it seems
cleaner).

The files created after running the DeployTask are...

{webapps}/ciderbob-website/ciderbob-website.war

{webapps}/ciderbob-website/com/ciderbob/dao/*.class

{webapps}/ciderbob-website/com/ciderbob/tags/*.class

(note none of my jsp files or images are present!)

Why did it put ciderbob-website.war INSIDE a ciderbob-website directory? Or
more to the point, why does Tomcat not expand all of the contents? If I
manually copy the war file to {webapps} it all works properly!!?!

Here is my full ant build file...

Any help would be very much appreciated.

Cheers,

Rob.



<?xml version="1.0" encoding = "UTF-8"?>

<project name="ciderbob-common" default="build" basedir=".">

<property name="src" location="./src"/>

<property name="deploy" location="./deploy"/>

<property name="warfile" location="${deploy}/ciderbob-website.war"/>

<property name="web-lib.dir" location="./libs" />

<property name="common-lib" location="../common/bin/lib"/>

<property name="webcontent.dir" location="./WebContent"/>

<property name="web-inf.dir" location="${webcontent.dir}/WEB-INF"/>

<property name="meta-inf.dir" location="${webcontent.dir}/META-INF"/>

<property name="local.manager.url" value="http://localhost:8080/manager"/>

<property name="local.manager.username" value="admin"/>

<property name="local.manager.password" value="yeaRight!"/>

<property name="local.deploy.path" value="/ciderbob-website"/>

<property name="local.war" value="file://${deploy}/"/>

<target name="deploy-local" depends="build">

<!--

You must copy the server/lib/catalina-ant.jar from Tomcat 5

directory into the lib directory of your Ant installation to

use these tasks. (also had to add to eclipse ant path!?)

Also requires manager privileges with Tomcat - edit

conf/tomcat-users.xml to add manager privileges for a username

and password.

-->

<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>

<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask"/>

<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>

<undeploy url="${local.manager.url}"

username="${local.manager.username}"

password="${local.manager.password}"

path="${local.deploy.path}" failonerror="no"/>

<!-- this results in the following files being created

{webapps}/ciderbob-website/ciderbob-website.war

{webapps}/ciderbob-website/com/ciderbob/dao/*.class

{webapps}/ciderbob-website/com/ciderbob/tags/*.class

Why did it put ciderbob-website.war INSIDE a ciderbob-website

directory? Or more to the point, why does Tomcat not expand all of

the contents? If I manually copy the war file to {webapps} it all

works properly!!?!

-->

<deploy url="${local.manager.url}"

username="${local.manager.username}"

password="${local.manager.password}"

path="${local.deploy.path}"

localWar="${local.war}"

alwayslog="yes"

/>

<reload url="${local.manager.url}"

username="${local.manager.username}"

password="${local.manager.password}"

path="${local.deploy.path}"/>

</target>

<target name="build" depends="Initialize, Compile, War">

<echo message="Building..."/>

</target>

<target name="Initialize">

<echo message="Initialising..."/>

<delete dir="${deploy}"/>

<mkdir dir="${deploy}"/>

</target>

<path id="classpath">

<fileset dir="${common-lib}">

<include name="**/*.jar"/>

</fileset>

<fileset dir="${web-lib.dir}">

<include name="**/*.jar"/>

</fileset>

</path>

<echo message="Classpath... ${classpath}"/>

<target name="Compile" depends="Initialize">

<depend srcDir="${common-lib}">

</depend>

<echo message="Compiling..."/>

<javac srcdir="${src}" destdir="${deploy}" includes="**/*.java"
excludes="**/Test*.java">

<classpath refid="classpath"/>

</javac>

</target>

<target name="War" depends="Initialize, Compile">

<echo message="Generating War file..."/>

<war destfile="${warfile}" webxml="${web-inf.dir}/web.xml">

<classes dir="${src}" includes="**/*.xml" />

<classes dir="${deploy}" includes="**/*.class" />

<fileset dir="${webcontent.dir}">

<include name="**/*"/>

</fileset>

<lib dir="${web-lib.dir}" includes="**/*.jar" />

<lib dir="${common-lib}" includes="**/*.jar" />

</war>

</target>

</project>

Re: deploy task to Tomcat partially works

Posted by Steve Loughran <st...@apache.org>.
Rob Wilson wrote:
> Hi Steve,
> 
> Thanks for the suggestions, as it turns out I should have mentioned that I
> am running Vista - it turned out to be permission problems in the webapps
> directory (doh!), one for the book?! ;-)

checking perms is a nightmare in java, and windows ACLs are a mystery to 
most people, and a PITA to actually code for in Win32 code.

> Incidentally, tell me more about your book - I often find that this Ant 'the
> definitive guide' doesn't go in to enough information.

"Ant in Action" is the most up to date and thorough book on developing 
and testing in ant. It was written against Ant1.7 and looks at the 
problems of
   -scaling up big projects
   -deployment
   -post-deployment testing
   -EJB

It isnt an attempt to replicate what is in the online docs, the 
reference pages, because that would be a waste of paper, money and time. 
  Instead it is more about how to build, test, deploy and test again, 
big server-side applications under Ant. We also view is as the 
documentation of my work project's build process, although some of the 
stuff we do there (building RPM files and testing them over SSH) is 
probably too

see more at http://antbook.org/

-steve

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: deploy task to Tomcat partially works

Posted by Rob Wilson <ne...@gmail.com>.
Hi Steve,

Thanks for the suggestions, as it turns out I should have mentioned that I
am running Vista - it turned out to be permission problems in the webapps
directory (doh!), one for the book?! ;-)

Incidentally, tell me more about your book - I often find that this Ant 'the
definitive guide' doesn't go in to enough information.

Cheers,
Rob.

Re: deploy task to Tomcat partially works

Posted by Steve Loughran <st...@apache.org>.
Rob Wilson wrote:
> Hi Steve,
> 
> Thank you for the tips, for some strange reason the file never gets
> created?! I have included verbose in the copy task, with the output I
> copied+paste the source file and destination dir into explorer to confirm
> the source file and destination directory exists...
> 
> I assume it's because of the c:/program files bit? -  I also have drive E on
> my machine, if I remove c: it copies to e:/Program Files/Apache Software
> Foundation/Tomcat 5.5/webapps ok.  So whats the format to force it to go to
> c:.... ?
> 
> Cheers,
> Rob.
> 
> <property name="local.tomcat.webapp.path" value="c:/Program Files/Apache
> Software Foundation/Tomcat 5.5/webapps"/>


1. You could change that to <property location="C:/..." > and then 
<echo> out the values to see what path Ant is thinking of here.

2. Try using c:\program files\apache software foundation\tomcat 
5.5\webapps instead of forward slashes
> 
> <copy todir="${local.tomcat.webapp.path}"
> 
> file="${warfile}"
> 
> failonerror="yes"
> 
> overwrite="yes"
> 
> verbose="yes"/>

looks good to me.



-- 
Steve Loughran                  http://www.1060.org/blogxter/publish/5
Author: Ant in Action           http://antbook.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: deploy task to Tomcat partially works

Posted by Rob Wilson <ne...@gmail.com>.
Hi Steve,

Thank you for the tips, for some strange reason the file never gets
created?! I have included verbose in the copy task, with the output I
copied+paste the source file and destination dir into explorer to confirm
the source file and destination directory exists...

I assume it's because of the c:/program files bit? -  I also have drive E on
my machine, if I remove c: it copies to e:/Program Files/Apache Software
Foundation/Tomcat 5.5/webapps ok.  So whats the format to force it to go to
c:.... ?

Cheers,
Rob.

<property name="local.tomcat.webapp.path" value="c:/Program Files/Apache
Software Foundation/Tomcat 5.5/webapps"/>

<property name="deploy" location="./deploy"/>

<property name="warfile" location="${deploy}/ciderbob-website.war"/>

<echo message="deploy-local - copying ${warfile} to ${
local.tomcat.webapp.path}..."/>

<copy todir="${local.tomcat.webapp.path}"

file="${warfile}"

failonerror="yes"

overwrite="yes"

verbose="yes"/>



On 10/31/07, Steve Loughran <st...@apache.org> wrote:
>
> Rob Wilson wrote:
> > Hi All,
> >
> > I have written my first Ant script from scratch, using google and the
> > O'reilly definitive guide.  I'm mostly happy with what I have ended up
> with,
> > however when I try to use the Tomcat DeployTask my application is not
> > deployed as expected.
> >
> > If I manually copy my war file to the webapps directory everything is
> fine,
> > so I really would like to understand how to use ant to deploy using the
> > Tomcat task (rather than copying directly to the webapp folder - it
> seems
> > cleaner).
>
>
> Speaking as the author of the alternative book, I'd argue in favour of
> deploying by copying the file.
>
> -its not any cleaner
> -its significantly less brittle
> -it lets you deploy in a secure environment
> -it ports to jboss, glassfish, etc, simply by changing the target dir.
> -you can undeploy using <delete> even if the application is already
> undeployed (whereas the tomcat tasks raise an error)
>
> the tomcat tasks (from the tomcat team) generates HTTP command to talk
> to the tomcat manager. Which means that the management API needs to be
> made visible.
>
> Just stick to using <copy>
>
> -Steve
>
> ps:
>
> > <target name="War" depends="Initialize, Compile">
> >
> > <echo message="Generating War file..."/>
> >
> > <war destfile="${warfile}" webxml="${web-inf.dir}/web.xml">
> >
> > <classes dir="${src}" includes="**/*.xml" />
> >
> > <classes dir="${deploy}" includes="**/*.class" />
> >
> > <fileset dir="${webcontent.dir}">
> >
> > <include name="**/*"/>
> >
> > </fileset>
> >
> > <lib dir="${web-lib.dir}" includes="**/*.jar" />
> >
> > <lib dir="${common-lib}" includes="**/*.jar" />
>
> > </war>
>
> There's no point asking for **/*.jar, as webapps only go one level deep.
> You need your lib directory to be flat before building the WAR.
>
> -steve
>
> --
> Steve Loughran                  http://www.1060.org/blogxter/publish/5
> Author: Ant in Action           http://antbook.org/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
Regards,
Rob Wilson

Re: deploy task to Tomcat partially works

Posted by Steve Loughran <st...@apache.org>.
Rob Wilson wrote:
> Hi All,
> 
> I have written my first Ant script from scratch, using google and the
> O'reilly definitive guide.  I'm mostly happy with what I have ended up with,
> however when I try to use the Tomcat DeployTask my application is not
> deployed as expected.
> 
> If I manually copy my war file to the webapps directory everything is fine,
> so I really would like to understand how to use ant to deploy using the
> Tomcat task (rather than copying directly to the webapp folder - it seems
> cleaner).


Speaking as the author of the alternative book, I'd argue in favour of 
deploying by copying the file.

-its not any cleaner
-its significantly less brittle
-it lets you deploy in a secure environment
-it ports to jboss, glassfish, etc, simply by changing the target dir.
-you can undeploy using <delete> even if the application is already 
undeployed (whereas the tomcat tasks raise an error)

the tomcat tasks (from the tomcat team) generates HTTP command to talk 
to the tomcat manager. Which means that the management API needs to be 
made visible.

Just stick to using <copy>

-Steve

ps:

> <target name="War" depends="Initialize, Compile">
> 
> <echo message="Generating War file..."/>
> 
> <war destfile="${warfile}" webxml="${web-inf.dir}/web.xml">
> 
> <classes dir="${src}" includes="**/*.xml" />
> 
> <classes dir="${deploy}" includes="**/*.class" />
> 
> <fileset dir="${webcontent.dir}">
> 
> <include name="**/*"/>
> 
> </fileset>
> 
> <lib dir="${web-lib.dir}" includes="**/*.jar" />
> 
> <lib dir="${common-lib}" includes="**/*.jar" />

> </war>

There's no point asking for **/*.jar, as webapps only go one level deep. 
You need your lib directory to be flat before building the WAR.

-steve

-- 
Steve Loughran                  http://www.1060.org/blogxter/publish/5
Author: Ant in Action           http://antbook.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org