views:

191

answers:

2

Hi,

I am working on a webapplication and I do most of the XHTML stuff in an editor. Every once in a while I froget to close a tag or mess up the nesting (we all get distracted sometimes ;-)).

So I commpile, package and run my webapp (using maven mvn clean package jetty:run-war only to notice that displaying the view (where I messed up the jsp) fails with an exception while trying to render.

So I wondered: Is there some tool that I can include into my build-cycle that automatically catches and rectifies those careless mistakes?

+1  A: 

There is the Maven CheckStyle plugin that looks at certain style rules in Java and other languages. It is customisable so you can add other rules. I can't say for sure that it will catch unclosed tags but this may be the place to start.

Using an IDE like Ecplipse or Netbeans will highlight any invalid code also. So you can actually see a red mark on the page as you type. That may be even more effective.

Vincent Ramdhanie
THanks Vincent. I am actually using Springsource Tool Suite which is a special version of Eclipse. I may have neglected the error markers, but a tool that is IDE-agnostic would of course be preferrable. Checkstyle seems to be a dead end here:http://old.nabble.com/JSP-Checking-td21349372.html
er4z0r
+1  A: 

Maybe a regular xml checker would do the trick. After all a JSP file is if properly written valid xml.

Patrick Cornelissen
Well I'm not only into a "fail early" but ideally the tool (tm) would also correct simple problems like nesting. Meanwhile I've found a jtidy-maven-plugin but it does not seem to be very actively maintained. (First impression looking at the timestamps of last changes)
er4z0r
A tool won't help you in closing tags, there are a lot of situations where a tool will add to few or too many elements to the surround unclosed tag. (Depending on a the kind of algorithm used to find the right closing spot)
Patrick Cornelissen