ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aravapalli, Udaya" <Udaya.Aravapa...@McKesson.com>
Subject RE: invoking ANT from JSP/Servlet
Date Tue, 14 May 2002 16:38:56 GMT
Thanks A Lot. This is very helpful.
Uday

-----Original Message-----
From: Hal Hildebrand (web) [mailto:Hal.Hildebrand@hellblazer.com]
Sent: Tuesday, May 14, 2002 11:14 AM
To: Ant Users List
Subject: Re: invoking ANT from JSP/Servlet


Use Ant's own execution mechanism.  Here's a simple Applet example:

import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.ExecTask;
import org.apache.tools.ant.types.Commandline;

import java.applet.Applet;
import java.awt.*;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URL;

public class AntApplet extends Applet implements Runnable {
    private Button execute;
    URL theURL;
    Thread runner;
    TextArea ta;

    public void init() {
        ta = new TextArea("", 7, 70);
        ta.setEditable(false);
        execute = new Button("Execute");
        setLayout(new BorderLayout());
        add("South", execute);
        add("Center", ta);
    }


    public void start() {
        if (runner == null) {
            runner = new Thread(this);
            runner.start();
        }
    }

    public void stop() {
        if (runner != null) {
            runner.stop();
            runner = null;
        }
    }

    public void run() {
        PrintStream ps = new PrintStream(new TaOutputStream());
        Project project = new Project();
        BuildLogger logger = new DefaultLogger();
        logger.setMessageOutputLevel(Project.MSG_INFO);
        logger.setOutputPrintStream(ps);
        logger.setErrorPrintStream(ps);
        logger.setEmacsMode(true);
        project.addBuildListener(logger);
        ExecTask exec = new ExecTask();
        exec.setProject(project);
        exec.setExecutable("ant.bat");
        Commandline.Argument arg = exec.createArg();
        arg.setLine("-buildfile d:/work/build.xml");
        exec.execute();
        ps.flush();
    }

    class TaOutputStream extends OutputStream {
        TaOutputStream() {
            super();
        }
        public void write(int b) throws IOException {
            byte[] bytes = new byte[] {(byte) b};
            String out = new String(bytes);
            ta.append(out);
        }
        public void write(byte[] b, int off, int len) throws IOException
{
            String out = new String(b, off, len);
            ta.append(out);
        }
    }
}

----- Original Message -----
From: "Aravapalli, Udaya" <Udaya.Aravapalli@McKesson.com>

> Hi
>
> Could anyone please tell me how to invoke ANT from a JSP/Servlet.I
> think executing Runtime.getRuntime().exec will do it. But as this is
> not a preferable way of invoking it, could you suggest an elegant way
of
> doing this.
> thanks
> Uday
>
>
> --
> To unsubscribe, e-mail:
<mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:ant-user-help@jakarta.apache.org>
>
>
>


--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message