Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Compiling Java from Java

Thread view: 
Malcolm Ryan - 10 Jan 2006 23:51 GMT
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 - 10 Jan 2006 23:59 GMT
> 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
James Westby - 11 Jan 2006 00:34 GMT
>>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?
[quoted text clipped - 8 lines]
>
> Malcolm

Using ant -

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


James
Roedy Green - 11 Jan 2006 01:39 GMT
>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
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Ranganath Kini - 11 Jan 2006 04:31 GMT
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
hiwa - 11 Jan 2006 06:29 GMT
> 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
hiwa - 11 Jan 2006 06:34 GMT
S.s.s.sorry, no example code there!
Thomas Weidenfeller - 11 Jan 2006 09:26 GMT
> 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
Signature

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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.