Jetty has a sexy new plugin for Ant that has the same features as the Maven plugin. So if you didn’t want to move from Ant to Maven, but you still want fast webapp development, now you can have it!
The Jetty Maven plugin greatly shortens your development cycle by allowing you to run jetty on your Maven webapp project without first having to assemble it into a fully-formed webapp. Moreover, it’s able to scan the webapp and automatically redeploy it when changes are detected (eg to class files, descriptors, jars etc). You can imagine how convenient that is when you’re using an IDE – you modify the source, the IDE compiles it in the background and your changes are then immediately reflected in the executing container.
Not everyone, however, is in a position to change to using Maven for building their webapps. Many folks are happy with (or are stuck with) using Ant, but would love to have the advantages of the Maven plugin.
Well, now they can! The Jetty Ant plugin brings you those same rapid development features.
Like the Maven plugin, the Ant plugin also directly supports configuration of jetty components like connectors, realms, request logs etc. Similarly, it also supports the use of a jetty.xml file to give you total control of the container environment for your webapp. As you’d expect, you can also specify a jetty-env.xml for doing fine-grained configuration of the JNDI resources.
Once you’ve done your initial configuration and setup it’s as easy as typing:

ant jetty.run

Big thanks to Jakub Pawlowicz and Sabre Holdings for this outstanding contribution to the Jetty project!


15 Comments

Jan Bartel · 09/03/2007 at 03:46

Not that I want to get into some kind of pissing contest here, but I just wanted to mention that the maven plugins don’t have quite the same feature set. 

For example, AFAIK, the jetty plugin is the only one which scans for changes and automatically redeploys.

However, I’m sure if that feature isn’t implemented yet, the Tomcat guys will be trying to catch up to us soon 🙂

yawmark · 18/03/2007 at 03:27

I’ve been unable to locate the jetty-ant JAR in *any* maven2 repository, as of 3/14/2007. Any suggestions?

Jan Bartel · 18/03/2007 at 21:16

The plugin is an optional extra and is currently not automatically built and pushed to the maven repos. For the moment, you have to download the jetty bundle from http://dist.codehaus.org/jetty and build it yourself – very simple (I also like the irony that it is built with maven 🙂 )

We’ll take a look to see if there’s a way we can push pre-built jars from the jetty/extras module to a repo.

cheers
Jan

Jim Cook · 23/03/2007 at 19:10

I would like to start up Jetty programmatically but with all of the features of the Maven plugin (e.g.. monitor directories). Is there a means to do this already?

I have just been down the road of creating the Jetty6RunWarExploded manually, but reached a deadend when this class because the webApp property is set using a @property attribute, and no javabean property is present.

Maybe I should look at the Ant task source? It would be cool if a launcher class that monitored directories (and allowed for multiple resource base directories) was part of Jetty proper and the maven and ant tasks could just delegate to that module. It would also allow someone who wants to programmatically start Jetty to have their cake also.

Bayanlar · 23/03/2007 at 19:29

Jetty Ant Plugin  Thank You

 

Best Regards…

Jan Bartel · 23/03/2007 at 23:33

I think we have what you want 🙂  Take a look at the wiki entry at http://docs.codehaus.org/display/JETTY/ContextDeployer.  The context deployer will do pretty much what the maven and ant plugins do in terms of deploying your webapp, watching for changes to it and automatically redeploying it when necessary.

cheers
Jan

Andreas Binder · 08/05/2007 at 10:00

I’d like to start jetty with additional vm parameters.
Is it possible to put such parameters to the Jetty Ant Plugin?

Best regards Andreas

Jakub Pawlowicz · 09/05/2007 at 07:34

Hi Andreas,

I believe there are at least two ways to do that:

  1. Provide your VM args via ANT_OPTS environment property – your args will be available to the whole ant process;
  2. Execute your Jetty task in a separate ant process. You can do it via ‘exec’ task in ant. It allows you to specify VM args directly from the ant script.
    Please note, that it doesn’t work well on Windows OS, because of some nasty bug (subprocess won’t close if you close the parent process).

As you can see there’s no way to specify VM args in the jetty task itself, which is because the ant plugin is not executed in a separate process.
However, we use both approaches to enable Java debugging for our web application and it works perfectly well.

I hope that answers your question.

Best Regards,
Jakub Pawlowicz

Andreas Binder · 14/05/2007 at 15:31

Hi Jacub,

thanks for the suggestions. I think, in using the plugin for debugging and testing this is a quite good solution.

Best Regards,
Andreas

Anonymous · 23/05/2007 at 22:20

Hey.

More on Ant Scripts in this non-profit resource on building large scale java applications:

<a href="http://coderslog.com/Ant_Scripts">Ant Script Samples</a>

Robert Kirkpatrick · 05/03/2010 at 04:47

Newbie question:
How can http_requests be handled in Ant when running Jetty?
Regards,
Robert.

Jan · 05/04/2010 at 13:45

Robert,

I’m not sure I understand your question. The wiki page at http://docs.codehaus.org/display/JETTY/Ant+Jetty+Plugin describes how to configure jetty connectors to accept HTTP requests when running jetty via the ant plugin.

cheers,

Jan

Robert Kirkpatrick · 12/04/2010 at 11:58

Jan,
I am looking for (a set of) ant tasks enabling the mapping of http incoming request parameters onto ant properties. I realize this is currently not the scope of the Jetty plug-in.
I found a Listener task in Anteater which does that but with Tomcat.
Another similar though limited attempt is Antserver in Antcontrib.
Regards,
Robert.

Jan Bartel · 13/04/2010 at 07:48

Robert,

Interesting! I haven’t heard of such a set of ant tasks before. If you come across anyone willing to contribute an impl for Jetty, please email jetty-dev@eclipse.org and let us know.

cheers,

Jan

Sam · 22/06/2011 at 03:25

I am struggling with setting UserRealm from ant script. Do you have an example?

Comments are closed.