Compile java files programmatically

Discussion in 'Java' started by bigbinc, May 20, 2004.

  1. bigbinc

    bigbinc Guest

    I need to compile large groups of java files programmatically. I have
    come up with two thread safe options.

    1. use the ANT api and call the proper 'javac' tasks(no XML)?

    2. use tomcat's compile engine?


    I know I could use just 'javac'.

    I know I could use just 'Runtime.exec'.

    I know I could use just a bash script.
    bigbinc, May 20, 2004
    #1
    1. Advertising

  2. bigbinc

    Chris Smith Guest

    bigbinc wrote:
    > I need to compile large groups of java files programmatically. I have
    > come up with two thread safe options.


    Did you have a question, or did you just want to share that information
    with us?

    In any case, if you're looking for comments, then using Tomcat to
    compile classes that aren't generated from JSP pages is rather
    questionable. It's an unneeded extra level of indirection. Ant is a
    tool designed for this purpose and would probably work fine.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, May 20, 2004
    #2
    1. Advertising

  3. bigbinc

    Neal Gafter Guest

    bigbinc wrote:
    > I need to compile large groups of java files programmatically.


    Place tools.jar on your classpath and invoke

    public int com.sun.tools.javac.Main.compile(String[] args);
    or
    public int com.sun.tools.javac.Main.compile(String[] args,
    PrintWriter out);

    One simple way to put tools.jar on your classpath is to put a copy of it into
    $JDK/jre/lib/endorsed/tools.jar
    Neal Gafter, May 20, 2004
    #3
  4. bigbinc

    Liz Guest

    "bigbinc" <> wrote in message
    news:...
    > I need to compile large groups of java files programmatically. I have
    > come up with two thread safe options.
    >
    > 1. use the ANT api and call the proper 'javac' tasks(no XML)?
    >
    > 2. use tomcat's compile engine?
    >
    >
    > I know I could use just 'javac'.
    >
    > I know I could use just 'Runtime.exec'.
    >
    > I know I could use just a bash script.


    so do it then
    Liz, May 21, 2004
    #4
  5. bigbinc

    bigbinc Guest

    Neal Gafter <> wrote in message news:<>...
    > bigbinc wrote:
    > > I need to compile large groups of java files programmatically.

    >
    > Place tools.jar on your classpath and invoke
    >
    > public int com.sun.tools.javac.Main.compile(String[] args);
    > or
    > public int com.sun.tools.javac.Main.compile(String[] args,
    > PrintWriter out);
    >
    > One simple way to put tools.jar on your classpath is to put a copy of it into
    > $JDK/jre/lib/endorsed/tools.jar


    Are these deprecated? for 1.4.2, and to the other posters, what are
    your thoughts on these methods? Have you tried compiling java
    programs through a network for example? I need something more than
    just using ANT through the default build.xml.
    bigbinc, May 21, 2004
    #5
  6. bigbinc

    Sudsy Guest

    bigbinc wrote:
    <snip>
    > Are these deprecated? for 1.4.2, and to the other posters, what are
    > your thoughts on these methods? Have you tried compiling java
    > programs through a network for example? I need something more than
    > just using ANT through the default build.xml.


    Again, why are you so sure? You mentioned "compiling java programs
    through a network" but what do mean specifically? If the sources
    are available on NFS-mounted filesystems then there's no problem.
    Ant even has a task called <FTP> which you could use to download
    source, compile it and FTP it back. This task is often used to
    deploy apps to app servers, BTW.
    Have you fully investigated the facilities provided by ant? I'd
    hate to see you reinventing the wheel.
    Sudsy, May 21, 2004
    #6
  7. bigbinc

    Roedy Green Guest

    Roedy Green, May 21, 2004
    #7
  8. bigbinc

    Neal Gafter Guest

    bigbinc wrote:
    > Neal Gafter <> wrote in message news:<>...
    >
    >>bigbinc wrote:
    >>
    >>>I need to compile large groups of java files programmatically.

    >>
    >>Place tools.jar on your classpath and invoke
    >>
    >> public int com.sun.tools.javac.Main.compile(String[] args);
    >>or
    >> public int com.sun.tools.javac.Main.compile(String[] args,
    >> PrintWriter out);
    >>
    >>One simple way to put tools.jar on your classpath is to put a copy of it into
    >>$JDK/jre/lib/endorsed/tools.jar

    >
    >
    > Are these deprecated? for 1.4.2, and to the other posters, what are
    > your thoughts on these methods? Have you tried compiling java
    > programs through a network for example? I need something more than
    > just using ANT through the default build.xml.


    No, these are not deprecated. These methods will stick around for a very long time.
    Neal Gafter, May 21, 2004
    #8
  9. Neal Gafter wrote:
    >>> Place tools.jar on your classpath and invoke
    >>>
    >>> public int com.sun.tools.javac.Main.compile(String[] args);
    >>> or
    >>> public int com.sun.tools.javac.Main.compile(String[] args,
    >>> PrintWriter out);

    []
    >> Are these deprecated? for 1.4.2, and to the other posters, what are
    >> your thoughts on these methods? Have you tried compiling java
    >> programs through a network for example? I need something more than
    >> just using ANT through the default build.xml.

    >
    >
    > No, these are not deprecated. These methods will stick around for a
    > very long time.


    Quite the opposite. These methods are an undocumented internal implementation
    detail of Sun's SDK! They could disappear at *any* time without prior notice!

    That's why there's an official compiler API being planned:
    http://www.jcp.org/en/jsr/detail?id=199
    Michael Borgwardt, May 21, 2004
    #9
  10. bigbinc

    Carl Howells Guest

    Michael Borgwardt wrote:
    >
    > Quite the opposite. These methods are an undocumented internal
    > implementation
    > detail of Sun's SDK! They could disappear at *any* time without prior
    > notice!
    >
    > That's why there's an official compiler API being planned:
    > http://www.jcp.org/en/jsr/detail?id=199


    While having an official interface is a good thing... Do you realize
    who you replied to? Neal Gafter maintains javac for Sun. I suspect
    that means he knows how long those methods will be around. :)
    Carl Howells, May 21, 2004
    #10
  11. Carl Howells wrote:
    > While having an official interface is a good thing... Do you realize
    > who you replied to? Neal Gafter maintains javac for Sun. I suspect
    > that means he knows how long those methods will be around. :)


    O_O

    Well, I can't be expected to know that, can I?

    Anyway, I doubt even he can make a definitive staement about that beyond
    a timeframe of maybe 5 years. And that's for Sun's SDK, the methods don't
    even exist for others.
    Michael Borgwardt, May 21, 2004
    #11
  12. bigbinc

    Roedy Green Guest

    On Fri, 21 May 2004 18:47:29 +0200, Michael Borgwardt
    <> wrote or quoted :

    >
    >Quite the opposite. These methods are an undocumented internal implementation
    >detail of Sun's SDK! They could disappear at *any* time without prior notice!


    However, from a practical point of view, I don't think they will
    disappear. They are in the sun directory, because, quite sensibly, not
    every JVM implementation need provide a built-in compiler.

    Sun is reserving the right to change the interface without notice. If
    they changed that one, there would a lot of howling.

    At some point, probably sun should make the interface something
    official like JCE, plug-replaceable and optional.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, May 21, 2004
    #12
  13. bigbinc

    bigbinc Guest

    Neal Gafter <> wrote in message news:<>...
    > bigbinc wrote:
    > > I need to compile large groups of java files programmatically.

    >
    > Place tools.jar on your classpath and invoke
    >
    > public int com.sun.tools.javac.Main.compile(String[] args);
    > or
    > public int com.sun.tools.javac.Main.compile(String[] args,
    > PrintWriter out);
    >
    > One simple way to put tools.jar on your classpath is to put a copy of it into
    > $JDK/jre/lib/endorsed/tools.jar



    I am seeing more developers that work for 'Sun', 'IBM' speaking out in
    different forums, and we all know about the JBOSS fiasco, good to see
    you guys.
    bigbinc, May 22, 2004
    #13
  14. bigbinc

    Sudsy Guest

    bigbinc wrote:
    <snip>
    > I am seeing more developers that work for 'Sun', 'IBM' speaking out in
    > different forums, and we all know about the JBOSS fiasco, good to see
    > you guys.


    Would you be so kind as to inform those of us "great unwashed" what
    you mean by "the JBOSS fiasco"?
    While I admit to not being a big fan of JBoss due to their attempts
    at generating income, I'm unfamiliar with your claim.
    Clarification would be most appreciated.
    Sudsy, May 22, 2004
    #14
  15. bigbinc

    Roedy Green Guest

    On Fri, 21 May 2004 21:59:18 -0400, Berlin Brown
    <> wrote or quoted :

    >
    >I think it presents an interesting interface for compiling programs. If I
    >could compile programs programmatically, I could for example build a simple
    >'swing' application quickly, where output is directed to a textarea, or
    >compile programs through HTTP and html forms, or through databases(off of
    >the top of my head ideas, not very practical).


    And a much faster MAKE. You save the overhead of reloading the JVM for
    each compile.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, May 22, 2004
    #15
  16. bigbinc

    Sudsy Guest

    Re: JBOSS fiasco

    Berlin Brown wrote:
    <snip>
    > Keep up, they have been talking about it on slashdot for weeks now.


    Thanks for the link! Actually, I DO keep up, and posted about how my
    submission to their tightly-controlled forum was quashed after just
    a few days. My concerns seem to be echoed by others, another fact I
    noted.
    Doesn't "Professional Open Source" sound a bit odd? I'm hardly
    averse to people earning a decent living from their efforts, BTW.
    I just don't like the idea of individuals or organizations purporting
    their products to be "free" when they're not.
    Try to find a Usenet ng on JBoss!
    Can't find one? Want to know why?
    Do your own research and look at the applications, denials, and
    reasons for denial.
    Need I say more?
    Sudsy, May 22, 2004
    #16
  17. bigbinc

    Berlin Brown Guest

    Roedy Green wrote:

    > On Fri, 21 May 2004 18:47:29 +0200, Michael Borgwardt
    > <> wrote or quoted :
    >
    >
    > At some point, probably sun should make the interface something
    > official like JCE, plug-replaceable and optional.
    >


    I think it presents an interesting interface for compiling programs. If I
    could compile programs programmatically, I could for example build a simple
    'swing' application quickly, where output is directed to a textarea, or
    compile programs through HTTP and html forms, or through databases(off of
    the top of my head ideas, not very practical).

    --
    Berlin Brown
    Berlin Brown, May 22, 2004
    #17
  18. bigbinc

    Berlin Brown Guest

    Sudsy wrote:

    > bigbinc wrote:
    > <snip>
    >> I am seeing more developers that work for 'Sun', 'IBM' speaking out in
    >> different forums, and we all know about the JBOSS fiasco, good to see
    >> you guys.

    >
    > Would you be so kind as to inform those of us "great unwashed" what
    > you mean by "the JBOSS fiasco"?
    > While I admit to not being a big fan of JBoss due to their attempts
    > at generating income, I'm unfamiliar with your claim.
    > Clarification would be most appreciated.


    Keep up, they have been talking about it on slashdot for weeks now.

    http://osdir.com/Article832.phtml

    --
    Berlin Brown
    Berlin Brown, May 22, 2004
    #18
  19. bigbinc

    Neal Gafter Guest

    Michael Borgwardt wrote:
    > Quite the opposite. These methods are an undocumented internal
    > implementation
    > detail of Sun's SDK! They could disappear at *any* time without prior
    > notice!
    >
    > That's why there's an official compiler API being planned:
    > http://www.jcp.org/en/jsr/detail?id=199


    As you can see by following the link that you posted, I am the spec lead for
    jsr199. I am also the lead engineer for javac at Sun. It is because jsr199
    will not be included in 1.5 that we're documenting these methods for JDK 1.5,
    thereby committing to their continued existence for a long time.
    Neal Gafter, May 22, 2004
    #19
  20. On Sat, 22 May 2004 03:22:06 GMT, Neal Gafter wrote:

    >> http://www.jcp.org/en/jsr/detail?id=199

    ....
    >..It is because jsr199
    > will not be included in 1.5 that we're documenting these methods for JDK 1.5,


    Javadocs? (If so, are they
    online/downloadable yet?
    I did not see any references)

    > thereby committing to their continued existence for a long time.


    Is good. :)

    --
    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, May 22, 2004
    #20
    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. Nagaraj
    Replies:
    1
    Views:
    837
    Lionel B
    Mar 1, 2007
  2. timjowers
    Replies:
    7
    Views:
    4,307
    heyjude
    Feb 2, 2011
  3. Replies:
    1
    Views:
    436
    Cowboy \(Gregory A. Beamer\)
    Apr 11, 2008
  4. Carter
    Replies:
    2
    Views:
    490
    Carter
    Mar 4, 2009
  5. fAnSKyer
    Replies:
    2
    Views:
    516
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page