Compile java files programmatically

B

bigbinc

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.
 
C

Chris Smith

bigbinc said:
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
 
N

Neal Gafter

bigbinc said:
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
 
L

Liz

bigbinc said:
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
 
B

bigbinc

Neal Gafter said:
bigbinc said:
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.
 
S

Sudsy

bigbinc wrote:
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.
 
N

Neal Gafter

bigbinc said:
Neal Gafter said:
bigbinc said:
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.
 
M

Michael Borgwardt

Neal said:
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
 
C

Carl Howells

Michael said:
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. :)
 
M

Michael Borgwardt

Carl said:
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.
 
R

Roedy Green

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.
 
B

bigbinc

Neal Gafter said:
bigbinc said:
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.
 
S

Sudsy

bigbinc wrote:
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.
 
R

Roedy Green

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.
 
S

Sudsy

Berlin Brown wrote:
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?
 
B

Berlin Brown

Roedy said:
On Fri, 21 May 2004 18:47:29 +0200, Michael Borgwardt


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).
 
B

Berlin Brown

Sudsy said:
bigbinc wrote:


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
 
N

Neal Gafter

Michael said:
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.
 
A

Andrew Thompson

....
..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. :)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top