Hi, I don't know if it's been done already or not, but I wrote up a new ant task to run the Jasper JSP compiler (from the Tomcat project). I've attached it a source file for the task. It is already part of the org.apache.tools.ant.taskdefs package. I don't know if you have rules about people working in that namespace, but if you want to change the package go ahead. I hope it's useful. If you have any questions send me a message. Thanks Alex.
package org.apache.tools.ant.taskdefs; /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ import org.apache.tools.ant.BuildException; import org.apache.jasper.JspC; import org.apache.jasper.JasperException; import java.util.Vector; import java.util.Iterator; /** * This task runs the Jasper JSP compiler which is part of the Jakarta * Tomcat project (jakarta.apache.org/tomcat). You must make sure you * have your servlet.jar, webserver.jar and parser.jar in your CLASSPATH * in order for this task to work. * * You should look at the jsp compiler for more information on * documentation and the various options. * * Creation date: (14/07/01 5:51:47 PM) * @author: Alex Muc <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> */ public class JasperCompiler extends org.apache.tools.ant.Task { //-d e:/temp/output -webapp e:/cc/cc/cc/ /* <file> A file t -webapp <dir> A direct will rec where options include: -q Quite mode -v[#] Verbose mod -d <dir> Output Dire -dd <dir> Literal Out -p <name> Name of tar -c <name> Name of tar (only appli -mapped Generate se -die[#] Generate an If the numb -uribase <dir> The uri (Defaul -uriroot <dir> The roo against -webinc <file> Creates -webxml <file> Creates -ieplugin <clsid> Java */ private String WebApp; private String OutputDir; private String QuietMode; private String Verbosity; private String PackageName; private String ClassName; private String Mapped; private String ErrorNum; private String UriBase; private String UriRoot; private String WebInc; private String WebXML; private String IEPlugin; /** * JasperCompiler constructor comment. */ public JasperCompiler() { super(); } /** * Insert the method's description here. * Creation date: (14/07/01 5:55:43 PM) */ public void execute() throws BuildException { System.out.println("Jasper Compiler"); /* Usage: jspc <options> [--] <jsp files> where jsp files is any number of: <file> A file to be parsed as a jsp page -webapp <dir> A directory containing a web-app, all jsp pages will recursivly be parsed where options include: -q Quite mode (same as -v0) -v[#] Verbose mode (optional number is level, default is 2) -d <dir> Output Directory -dd <dir> Literal Output Directory. (package dirs will not be made) -p <name> Name of target package -c <name> Name of target class name (only applies to first JSP page) -mapped Generate separate write() calls for each HTML line in the JSP -die[#] Generate an error return code (#) on fatal errors. If the number is absent or unparsable it defaults to 1. -uribase <dir> The uri directory compilations shoule be relative to (Default is "/") -uriroot <dir> The root directory that uri files should be resolved against, (Default is the directory jspc is invoked from) -webinc <file> Creates partial servlet mapings for the -webapp option -webxml <file> Creates a complete web.xml when using the -webapp option. -ieplugin <clsid> Java Plugin classid for Internet Explorer */ Vector args = new Vector(); if (QuietMode != null) { args.add("-q"); } if (Verbosity != null) { args.add("-v" + Verbosity); } if (OutputDir != null) { args.add("-d"); args.add(OutputDir); } if (PackageName != null) { args.add("-p"); args.add(PackageName); } if (ClassName != null) { args.add("-c"); args.add(ClassName); } if (Mapped != null) { args.add("-m"); } if (ErrorNum != null) { args.add("-die" + ErrorNum); } if (UriBase != null) { args.add("-uribase"); args.add(UriBase); } if (UriRoot != null) { args.add("-uriroot"); args.add(UriRoot); } if (WebInc != null) { args.add("-webinc"); args.add(WebInc); } if (WebXML != null) { args.add("-webxml"); args.add(WebXML); } if (IEPlugin != null) { args.add("-ieplugin"); args.add(IEPlugin); } if (WebApp != null) { args.add("-webapp"); args.add(WebApp); } String []arg = new String [args.size()]; int i = 0; Iterator a = args.iterator(); while (a.hasNext()) { arg[i] = (String) a.next(); i ++; } System.out.println("Running Jasper with: " + args.toString()); try { JspC jspc = new JspC(arg, System.out); jspc.parseFiles(System.out); } catch (JasperException je) { System.err.print("error:"); System.err.println(je.getMessage()); } } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setClassname(String a) { ClassName = a; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setErrornum(String od) { ErrorNum = od; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setIeplugin(String a) { IEPlugin = a; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setMapped(String od) { Mapped = od; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setOutputdir(String od) { OutputDir = od; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setPackagename(String a) { PackageName = a; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setQuietmode(String a) { QuietMode = a; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setUribase(String od) { UriBase = od; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setUriroot(String a) { UriRoot = a; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setVerbosity(String od) { Verbosity = od; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setWebapp(String wa) { WebApp = wa; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setWebinc(String a) { WebInc = a; } /** * Insert the method's description here. * Creation date: (14/07/01 5:53:24 PM) * @param outputDir java.lang.String */ public void setWebxml(String a) { WebXML = a; } }
