Compiling Source Directly From A Program

Discussion in 'Java' started by Prakash Prabhu, Aug 21, 2003.

  1. 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
     
    Prakash Prabhu, Aug 21, 2003
    #1
    1. Advertising

  2. "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/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
     
    Jos A. Horsmeier, Aug 21, 2003
    #2
    1. Advertising

  3. 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
     
    Prakash Prabhu, Aug 21, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    1,423
  2. Shawn
    Replies:
    2
    Views:
    1,485
    Shawn
    Dec 6, 2006
  3. Replies:
    5
    Views:
    443
    Chris Hills
    Jun 21, 2007
  4. Ajinkya
    Replies:
    65
    Views:
    1,172
    Keith Thompson
    Oct 9, 2007
  5. cowsled
    Replies:
    0
    Views:
    308
    cowsled
    Dec 14, 2008
Loading...

Share This Page