KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > neu > ccs > jmk > sun > Javac1_3


1 // $Id: Javac1_3.java,v 1.1 2002/01/28 12:46:53 ramsdell Exp $
2

3 /*
4  * Copyright 2000 by Lachlan O'Dea
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package edu.neu.ccs.jmk.sun;
22
23 import com.sun.tools.javac.Main;
24 import edu.neu.ccs.jmk.Operator;
25 import edu.neu.ccs.jmk.CommandFailedException;
26 import java.io.*;
27
28 public final class Javac1_3 implements Operator
29 {
30
31    private static final int COMPILE_OK = 0;
32    private static final Main compiler = new Main();
33
34    public String JavaDoc getName()
35    {
36       return "Javac1_3";
37    }
38
39     public void exec(String JavaDoc[] args, PrintWriter out)
40        throws CommandFailedException
41     {
42        // it appears we can't specify an output stream with the new compiler
43

44        String JavaDoc[] argsWithClasspath = new String JavaDoc[args.length + 2];
45        argsWithClasspath[0] = "-classpath";
46        argsWithClasspath[1] = System.getProperty("java.class.path");
47        System.arraycopy(args, 0, argsWithClasspath, 2, args.length);
48        int errorCode = compiler.compile(argsWithClasspath);
49        if (errorCode != COMPILE_OK)
50        {
51       throw new CommandFailedException("Compiler returned: " + errorCode);
52        }
53     }
54
55 } // public class Javac1_3
56
Popular Tags