Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Compiling Source Directly From A Program

Reply
Thread Tools

Compiling Source Directly From A Program

 
 
Prakash Prabhu
Guest
Posts: n/a
 
      08-21-2003
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.

Thanks,
Prakash

 
Reply With Quote
 
 
 
 
Jos A. Horsmeier
Guest
Posts: n/a
 
      08-21-2003
"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
 
Reply With Quote
 
 
 
 
Prakash Prabhu
Guest
Posts: n/a
 
      08-21-2003
Jos A. Horsmeier wrote:
> 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


Thanks for the reply!
Indeed , sun.tools.javac.Main.compile is not static in my tools.jar .
I checked the tools.jar file and found the following signature
for sun.tools.javac.Main.compile :

public int compile(java.lang.String[] param1)

Thanks again,
Prakash


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling source code from another program cowsled Java 0 12-14-2008 05:25 PM
Compiling a C program through another C program Ajinkya C Programming 65 10-09-2007 06:58 PM
How to compile a C source file without using the C compiler directly ganesh.kundapur@gmail.com C Programming 5 06-21-2007 09:45 AM
Can Java program evoke and run a FORTRAN program directly? Shawn Java 2 12-06-2006 07:08 PM
Preview image directly on PC, save directly to HD Patrick M. Digital Photography 3 01-07-2004 08:29 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57