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
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
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
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.
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
> 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
S.s.s.sorry, no example code there!
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/