tags:

views:

881

answers:

3

Hello,

Can some describe the minimal conventional directory structure for a Java web app, and the minimal build.xml to get ant to build it, and make a war?

Target for today is deploy a Wicket app to Tomcat outside of an IDE, just with ant and my favourite text editor.

+2  A: 

Ours look like this:

web/
web/WEB-INF/   (sometimes we use a conf/ dir at the top level but this is minimal)
src/
lib/

The build.xml has three targets:

  • jsp: copies everything from web/ into the tomcat webapp folder and from lib/ into WEB-INF/lib
  • compile: compiles everything from src/ into WEB-INF/classes in the webapp
  • war: runs compile, jsp, and then zips the contents of the tomcat webapp into a warfile

This structure is a little bit informal and you can do it more cleanly by having a separate build directory for the warfile, and/or a separate compile directory, etc. Some people don't like the idea of deploying directly to the webapp instead of building a war first. But to get something up and running quickly, the above will do nicely.

Leigh Caldwell
+3  A: 

Maybe not the most minimalist possible, but the Tomcat project has an Application Developer's Guide with a section on source layout and a sample build.xml

Also, if you are starting a new project, you might want to check out Maven. With Maven, rather than crafting your own build scripts, you adhere to standard layout to do stuff, and then Maven figures out all the rest. It also manages dependencies, including its own. Learning curve is a bit steep, though.

Thilo
I'd vote up on the advice to refer to the Tomcat app dev guide. But a vote down for using maven :P
leif81
+1  A: 

You should check out maven. It's really complicated, but to build a war file it's simple, and there are plugins that will deploy the war to tomcat.

ScArcher2