File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Best practise for Maven for Web Project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Best practise for Maven for Web Project" Watch "Best practise for Maven for Web Project" New topic

Best practise for Maven for Web Project

Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
In your standard Web Application, you have WebContent (HTML, .CSS, javascript and JSPs) and Java source files.

Is it best practise in maven to have one pom for your entire web project (webcontent + Java Source files) or to have one pom for your web content and then one for your javasource files.
Your Java source files then get packaged to a jar and your WebContent is packaged as a War which depends on the Java Source Files packaged as jar.

Many thanks.

Peter Johnson

Joined: May 14, 2008
Posts: 5852

I has always seen the servlets and their helper classes appearing in the same projects with the static web content. Thus the classes end up in WEB-INF/classes. In a way this makes more sense because usually the Java sources and the static content are closely related. If the Java classes were packaged in a separate JAR file, one would usually assume that that JAR could be used in multiple projects, which in this instances is not the case.

Anyway, that is my 2 cents.

JBoss In Action
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

Unless I'm mistaken, you're considering a scenario where the static content of a webapp is being packaged and deployed separately from the dynamic stuff. JSPs, BTW are not static content - they're compiled into dynamic components, and therefore cannot be effectively deployed in a static content server.

There once was a practical performance reason for separating static and active services in J2EE, but that was long, long ago. Modern-day servers such as Tomcat can serve up CSS and HTML just as efficiently as Apache can, so there's no real reason to complicate matters by creating a separate static content bundle.

If you do choose to separate the 2, however, the "correct" way would be to make each package be a separate Maven project, since the Maven rule is 1 product output per project.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Best practise for Maven for Web Project
It's not a secret anymore!