Saturday, May 16, 2009

NetBeans 6.5.1 generates invalid web.xml

If you use NetBeans 6.5.1 and you want to add a new servlet to the project, the IDE generate an invalid web.xml file and you will be not able to deploy the application.

The problem
If you try to deploy the web application into an application container, then you get an exception like this:
org.apache.catalina.startup.ContextConfig applicationWebConfig
SEVERE: Parse error in application web.xml file at jndi:/localhost/XXXXXX/WEB-INF/web.xml
java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name XXXXXX


The solution
Solving this problem is very easy:
  1. Open your web.xml file and choose the XML view to see the xml code.
  2. Cut all <servlet-mapping> tags and put them back after the <servlet> tags.
After you redistribute and deploy your application, it will be start successfully.

No comments: