// update web.xml
String webFolderName = WebUtils.getWebFolderName(project);
IFile webFile = project.getFile(new Path(webFolderName + "/WEB-INF/web.xml"));
WebDocumentEditContext context = new WebDocumentEditContext(webFile);
try {
WebAppElement moduleElement = context.getWebAppElement();
// add new servlet definition
{
String servletClassName = serverPackageName + "." + serviceName + "Impl";
String pattern = "/" + module.getName() + "/" + serviceName;
// servlet
com.google.gdt.eclipse.designer.model.web.ServletElement servletElement =
new com.google.gdt.eclipse.designer.model.web.ServletElement();
moduleElement.addChild(servletElement);
servletElement.setName(serviceName);
servletElement.setClassName(servletClassName);
// servlet-mapping
com.google.gdt.eclipse.designer.model.web.ServletMappingElement servletMappingElement =
new com.google.gdt.eclipse.designer.model.web.ServletMappingElement();
moduleElement.addChild(servletMappingElement);
servletMappingElement.setName(serviceName);
servletMappingElement.setPattern(pattern);
}
// commit modifications
context.commit();