if (!javadir.exists()) {
System.err.println("Can't create '" + javadir + "' for some reason.");
return;
}
ClassDefinition classdef = new ClassDefinition(EXAMPLE_CODE_PACKAGE, EXAMPLE_CODE_CLASS);
classdef.setSuperClass(HttpServlet.class);
classdef.addImport(HttpServlet.class);
classdef.addImport(HttpServletRequest.class);
classdef.addImport(HttpServletResponse.class);
classdef.addImport(ServletException.class);
classdef.addImport(IOException.class);
MethodDefinition method = new MethodDefinition("service");
method.setPublic(true);
method.addThrowsClause(ServletException.class).addThrowsClause(IOException.class);
method.addArg(HttpServletRequest.class, "request");
method.addArg(HttpServletResponse.class, "response");
method.addLine("response.setContentType(\"text/plain\");");
method.addLine("response.getWriter().println(\"Hello World!\");");
classdef.addMethod(method);
File javafile = new File(javadir
, EXAMPLE_CODE_PACKAGE.replace('.', File.separatorChar) + File.separator + EXAMPLE_CODE_CLASS + ".java");
javafile.getParentFile().mkdirs();
PrintWriter java = new PrintWriter(javafile);
try {
classdef.write(java);
} finally {
java.close();
}
WebAppConfigurationBuilder wxmlb = new WebAppConfigurationBuilder();