f



Compiling Java from Java

I wish to write a Java program which can compile and run java source
code. Can this be done without resorting to OS-specific calls to javac?
I've seen suggestions that Ant might allow me to do this, but I've
looking through the Ant manual, I can't see anything about it. Any
hints?

Malcolm

0
1/10/2006 11:51:24 PM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

7 Replies
898 Views

Similar Articles

[PageSpeed] 45

Malcolm Ryan wrote:
> I wish to write a Java program which can compile and run java source
> code. Can this be done without resorting to OS-specific calls to javac?
> I've seen suggestions that Ant might allow me to do this, but I've
> looking through the Ant manual, I can't see anything about it. Any
> hints?

A little more research and I found the answer to my question.
Use com.sun.tools.javac.Main in tools.jar.

http://www.javaworld.com/javatips/jw-javatip131.html

Malcolm

0
1/10/2006 11:59:54 PM
Malcolm Ryan wrote:
> Malcolm Ryan wrote:
> 
>>I wish to write a Java program which can compile and run java source
>>code. Can this be done without resorting to OS-specific calls to javac?
>>I've seen suggestions that Ant might allow me to do this, but I've
>>looking through the Ant manual, I can't see anything about it. Any
>>hints?
> 
> 
> A little more research and I found the answer to my question.
> Use com.sun.tools.javac.Main in tools.jar.
> 
> http://www.javaworld.com/javatips/jw-javatip131.html
> 
> Malcolm
> 

Using ant -

http://www-128.ibm.com/developerworks/websphere/library/techarticles/0502_gawor/0502_gawor.html


James
0
jw2328 (121)
1/11/2006 12:34:52 AM
On 10 Jan 2006 15:51:24 -0800, "Malcolm Ryan" <malcolm.ryan@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>I wish to write a Java program which can compile and run java source
>code. Can this be done without resorting to OS-specific calls to javac?
>I've seen suggestions that Ant might allow me to do this, but I've
>looking through the Ant manual, I can't see anything about it. Any
>hints?

see http://mindprod.com/jgloss/javacexe.html#MAIN
-- 
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
0
1/11/2006 1:39:35 AM
Looks like the Sun development team heard of your requirement and they
have added a new feature in JDK 6 codenamed "Mustang" called - Java
Compiler API.

The following link shud give u more information:
http://jcp.org/en/jsr/detail?id=199

And here is an early draft of the Java Compiler API, download the file
( I guess u also need to download the latest binary build of JDK 6 to
run the examples).

http://jcp.org/aboutJava/communityprocess/edr/jsr199/index.html

It carries an example of executing Java code off a string. Just as u
wanted. ;-)

Hope this helps!

Best Regards,
Ranganath Kini

0
1/11/2006 4:31:40 AM
> Java Compiler API.
Good news!

Description and example code are found in the javac man page:
jdk1.6.0/docs/tooldocs/solaris/javac.html#proginterface

0
HGA03630 (564)
1/11/2006 6:29:51 AM
S.s.s.sorry, no example code there!

0
HGA03630 (564)
1/11/2006 6:34:09 AM
Ranganath Kini wrote:
> Looks like the Sun development team heard of your requirement and they
> have added a new feature in JDK 6 codenamed "Mustang" called - Java
> Compiler API.

They promised to do that for a long time. The API was originally 
scheduled for Java 1.5. But all one got in 1.5 was basically the old 
method of calling the main method of the compiler.

Maybe they get around it this time.

Sometimes using a library like ASM or BCEL is an alternative to firing 
up the complete compiler. These libraries assemble and load byte code on 
the fly.

/Thomas
-- 
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
0
nobody89 (1641)
1/11/2006 9:26:01 AM
Reply: