views:

1077

answers:

1

Hi,

I will use Apache Ant and Apache Ivy to build a web application which is deployed to a local Tomcat instance (during development). I have some questions:

  1. I want to grab most of my dependencies from the Maven2 repositories which works fine, but for the servlet JAR I would like to use the one Tomcat provides. Is there a way to do that using Ivy? And what do you think about doing so?
  2. I download the Ivy JAR using Ant to "auto install" it into ~/.ivy2/jar/ivy.jar and I have the Ivy cache at its default location ~/.ivy2/cache . I keep both of these locations outside the project directory on purpose. Good idea?
  3. Do you have an example of how to use Ant for the build file, Ivy to resolve dependencies, compile a WAR file and deploy it to a local (at the moment) Tomcat installation? I'm looking for something to have as a best practice which I then can modify further.
  4. I've used some examples on the Ivy web site and modified them. Is there anything I should change? The build file can be seen at http://pastebin.com/f7b34abc2 , as I had problems pasting XML code in here.

(Please notice that I'm not looking for the suggestion that I should use Maven2, even if the suggestion is well intended.)

+3  A: 

At runtime tomcat will use it's own away as it's classloader will exclude any jar with javax.servlet.Servlet in it. If you really really must compile against it you will have to do it in the ant script, and either copy it or reference it in the compile classpath.

On the other stuff, downloading ivy on demand is a good idea as it will prevent checking the ivy jar into the project scm repo as I have done in the past, whether you download it to the project directory or the user home is a matter of personal preference. The ivy cache on the other hand should be shared with other projects so the user home directory is a good location.

Building the war file isn't any different once you have done ivy:retrieve as the jar files required will be local to the project, just use the ant war task to create the war as normal. This is one advantage to ivy, that once the jars are downloaded it has no more to do in the build and you can just use ant to compile and package your project.

Had a quick look at your build file, looks perfectly sane.

Hope this helps.

Gareth Davis
Thank you for your answer! It helps a lot. Then I'll use the servlet api jar available in the Maven2 repositories for compilation as Tomcat will use its own anyway. That was really the hardest part so far, glad you shed some light on it! :-)
DeletedAccount