Compiling Source Directly From A Program

P

Prakash Prabhu

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/developer/JDCTechTips/2003/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
 
J

Jos A. Horsmeier

Prakash Prabhu said:
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/developer/JDCTechTips/2003/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
 
P

Prakash Prabhu

Jos said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top