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 / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

Compiling code at runtime

Thread view: 
Jo Vermeulen - 25 May 2004 09:39 GMT
Hello,

I was wondering if Java supports a feature of C# (or .NET in general),
namely compiling code at runtime.

This is nice for scripting purposes. Users can script the application in
real programming languages (such as C#, VB.NET, ...). This is done using
the System.CodeDom.Compiler namespace, if I recall correctly.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fSystemCodeDomCompiler.asp


Is such a feature available for any version of Java (perhaps JDK 1.5 beta
1)? Ofcourse it would then only be able to compile Java code.

Thanks in advance!

Signature

Jo Vermeulen
Student Computer Science at the tUL
email: jo@lumumba.luc.ac.be
www: http://lumumba.luc.ac.be/jo

Christophe Vanfleteren - 25 May 2004 09:47 GMT
> Hello,
>
[quoted text clipped - 4 lines]
> real programming languages (such as C#, VB.NET, ...). This is done using
> the System.CodeDom.Compiler namespace, if I recall correctly.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fSystemCodeDomCompiler.asp


> Is such a feature available for any version of Java (perhaps JDK 1.5 beta
> 1)? Ofcourse it would then only be able to compile Java code.
>
> Thanks in advance!

If you want scriptable applications, you don't need to compile code perse.

You can use one of the available scripting languages for the JVM, like
Beanshell: http://beanshell.org/

Or you could use the BSF (Bean Scripting Framework), which allows you to
plugin the scripting language of your choice.
http://jakarta.apache.org/bsf/

If you really need to compile a regular class, use the regular java
compiler:

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);

Signature

Kind regards,
Christophe Vanfleteren

Jo Vermeulen - 25 May 2004 10:10 GMT
Op Tue, 25 May 2004 08:47:16 +0000, schreef Christophe Vanfleteren:

<snip />

> If you want scriptable applications, you don't need to compile code perse.

It isn't about the compiling per se, but I wanted to script using a full
grown language, which is probably easier for programmers than to learn a
new scripting language.

> You can use one of the available scripting languages for the JVM, like
> Beanshell: http://beanshell.org/

Looks good, and seems to do what I want it to.

> Or you could use the BSF (Bean Scripting Framework), which allows you to
> plugin the scripting language of your choice.
[quoted text clipped - 9 lines]
>    public int com.sun.tools.javac.Main.compile(String[] args,
>                                               PrintWriter out);

Didn't know that. Is tools.jar included in the standard JDK?

Thanks for your quick reply!

Kind regards,

Signature

Jo Vermeulen
Student Computer Science at the tUL
email: jo@lumumba.luc.ac.be
www: http://lumumba.luc.ac.be/jo

Thomas Schodt - 25 May 2004 10:47 GMT
> Didn't know that. Is tools.jar included in the standard JDK?

Erm, don't you have a standard J2SDK installed?

Check what files exist under lib...
Jo Vermeulen - 25 May 2004 12:02 GMT
Op Tue, 25 May 2004 10:47:14 +0100, schreef Thomas Schodt:

>> Didn't know that. Is tools.jar included in the standard JDK?
>
> Erm, don't you have a standard J2SDK installed?
>
> Check what files exist under lib...

Wasn't at my PC this morning :-)

Checked it now, and indeed, it's there:

/opt/sun-jdk-1.5.0_beta1/lib/tools.jar

Kind regards,

Signature

Jo Vermeulen
Student Computer Science at the tUL
email: jo@lumumba.luc.ac.be
www: http://lumumba.luc.ac.be/jo



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



©2008 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.