Russell, People are talking about an API/JSR for exactly this situation. See http://groups.yahoo.com/group/javax_compiler for a bit more info.
Thanks, dims --- Russell Butek <[EMAIL PROTECTED]> wrote: > Hmmm... sun.tools.javac.Main is deprecated in JDK1.4. This means it'll > go away at some point (in a few years, so maybe we don't have to worry > about it). When it DOES go away, what will we do, then? > > Russell Butek > [EMAIL PROTECTED] > > > [EMAIL PROTECTED] on 06/05/2002 01:53:42 PM > > Please respond to [EMAIL PROTECTED] > > To: [EMAIL PROTECTED] > cc: > Subject: cvs commit: xml-axis/java/src/org/apache/axis/utils/compiler > Javac.java > > > > dims 2002/06/05 11:53:41 > > Modified: java/src/org/apache/axis/utils/compiler Javac.java > Log: > Use Reflection to avoid deprecation errors. > > NOTE: > com.sun.tools.javac.Main does not have an entry point for passing an > output stream to capture the compile errors. > So we use sun.tools.javac.Main entry-point in both environments. The > modern flag is needed to parse the output, > > Revision Changes Path > 1.8 +26 -5 xml- > axis/java/src/org/apache/axis/utils/compiler/Javac.java > > Index: Javac.java > =================================================================== > RCS file: /home/cvs/xml- > axis/java/src/org/apache/axis/utils/compiler/Javac.java,v > retrieving revision 1.7 > retrieving revision 1.8 > diff -u -r1.7 -r1.8 > --- Javac.java 15 Mar 2002 01:14:11 -0000 1.7 > +++ Javac.java 5 Jun 2002 18:53:41 -0000 1.8 > @@ -56,7 +56,6 @@ > package org.apache.axis.utils.compiler; > > import org.apache.axis.utils.JavaUtils; > - > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > > @@ -65,6 +64,9 @@ > import java.io.ByteArrayOutputStream; > import java.io.File; > import java.io.IOException; > +import java.io.OutputStream; > +import java.lang.reflect.Constructor; > +import java.lang.reflect.Method; > import java.util.ArrayList; > import java.util.List; > import java.util.NoSuchElementException; > @@ -75,7 +77,7 @@ > * > * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a> > * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a> > - * @version $Revision: 1.7 $ $Date: 2002/03/15 01:14:11 $ > + * @version $Revision: 1.8 $ $Date: 2002/06/05 18:53:41 $ > * @since 2.0 > */ > > @@ -120,9 +122,28 @@ > */ > public boolean compile() throws IOException { > ByteArrayOutputStream err = new ByteArrayOutputStream(); > - sun.tools.javac.Main compiler = new sun.tools.javac.Main(err, > "javac"); > - boolean result = > - compiler.compile(toStringArray(fillArguments(new > ArrayList()))); > + boolean result = false; > + > + try { > + // Create an instance of the compiler, redirecting output to > err > + Class c = Class.forName("sun.tools.javac.Main"); > + Constructor cons = > + c.getConstructor(new Class[] { OutputStream.class, > + String.class }); > + Object compiler = cons.newInstance(new Object[] { err, > + "javac" > }); > + // Call the compile() method > + Method compile = c.getMethod("compile", > + new Class [] { String[].class > }); > + Boolean ok = > + (Boolean) compile.invoke(compiler, > + new Object[] > {toStringArray(fillArguments(new ArrayList()))}); > + result = ok.booleanValue(); > + } catch (Exception cnfe){ > + log.error(JavaUtils.getMessage("noCompiler00"), cnfe); > + throw new RuntimeException(JavaUtils. > getMessage("noCompiler00")); > + } > + > this.errors = new ByteArrayInputStream(err.toByteArray()); > return result; > } > > > > ===== Davanum Srinivas - http://xml.apache.org/~dims/ __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com