"Prakash Prabhu" <> wrote in message news:rSZ0b.32$...
> Hi,
>
> I am new to programming in Java , although i have been working
> in C++ for some time.
> This mail is regarding the Java Tech Tip on Sun's site :
>
> http://developer.java.sun.com/develo.../tt0722.html#2
>
> When i tried running the program , i got the following error :
>
> D:\BeginningJava\Compiling a Java program from another
> program\RunIt.java:70: non-static method compile(java.lang.String[])
> cannot be referenced from a static context
> com.sun.tools.javac.Main.compile(
> ^
> 1 error
>
> Any pointers on what mistake I am doing would be highly useful to me.
The compile() method is not a static method. I once hacked the following,
after peeking the appropriate classes using reflection --
// create a new compiler; 'out' is an OutputStream
sun.tools.javac.Main c= new sun.tools.javac.Main(out, "javac");
// all arguments (originally on the command line
String[] args = { ... };
// fire up the compiler; if status == false, compilation failed
boolean status= c.compile(args);
AFAIK, the sun.tools.javac.Main class does not belong to the published API,
so things could change without notice.
kind regards,
Jos