Compile a java class from within another java program using tool.jar

Discussion in 'Java' started by Mathias Conradt, Sep 7, 2004.

  1. I need to compile a java class from within another java program.

    Using
    Runtime.getRuntime().exec("javac ...
    works fine. But I would like to user the javac class from Sun's
    tool.jar directly.

    When I try to compile just the same file using the Sun tool.jar:

    String arg[] = {"-sourcepath","c:/projects/pm/WEB-INF/src","-d","c:/tmp/pm","c:/path/to/class.java"};
    com.sun.tools.javac.Main.main(arg);

    it gives me the following short stack trace:
    "Error: Can't read <path_to_class.java>"

    Any idea what the problem might be? The java class to be compiled is
    given as absolute path and exists. I don't think that I have any other
    application using the file at the same time. And the path is also
    correct.

    Mathias
    Mathias Conradt, Sep 7, 2004
    #1
    1. Advertising

  2. Andrew Thompson, Sep 7, 2004
    #2
    1. Advertising

  3. Andrew Thompson wrote:
    > Try..
    > "C:/path/to/class.java"
    >
    > If that fails, try Linux. ;-)


    This didn't make any difference, but meanwhile I found the problem.

    Runtime.exec accepts a term including a wild card for the java files to
    be compiled: /path/to/Some*.java

    The compile-Method in tool.jar does not accept a wild card, therefore I
    had to list all one by one. But it's working. Fortunately it's just
    three files.

    Mathias
    Mathias Conradt, Sep 8, 2004
    #3
  4. On Wed, 08 Sep 2004 23:44:37 +0200, Mathias Conradt wrote:

    > The compile-Method in tool.jar does not accept a wild card, therefore I
    > had to list all one by one.


    Try giving it the name of a file containing
    the entire list of Java files to be compiled,
    one on each line. From memory, that works..

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
    Andrew Thompson, Sep 8, 2004
    #4
    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. cyril
    Replies:
    2
    Views:
    3,859
    cyril
    Aug 25, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    568
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,719
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,754
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    657
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page