ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Derricutt <>
Subject Re: Calling Ant from Java: An example please ?
Date Wed, 13 Feb 2002 20:38:44 GMT
Sounds like you're wanting to do something like a scripting language, but 
with proper compiled code?

Maybe you could look at BeanShell (, java scripting 
object, scripts are all in java, very easy to work with, basically you call 
*hunts for his code*:

import bsh.Interpreter;

public void runCode()
  String fromNativeApp = "Hello World";

  String code = "System.out.println(native)";

  Interpreter bsh = new Interpreter();

  bsh.set("native", fromNativeApp);


So, code is a String containing the code to run, note that it doesn't need 
to be in a procedure, but could be if you wanted.  This could easily to 
dynamically generated.

You then create an instance of the Interpreter class, expose any objects 
from the main program via .set(), and then .eval the code.

Its not as fast as native compiled code, but it sure is easy....


--On Wednesday, 13 February 2002 10:29 a.m. -0800 Jay Riddell 
<> wrote:

> I have an application where I need to dynamically generate Java source
> code, compile it, load it and then execute that code.  I see the Ant API
> as an excellent method to help me get this done.
> However, I haven't been able to get it to work.
> After setting everything up, I get the following exception:
>      [java] Exception in thread "main" java.lang.NullPointerException
>      [java]     at
>      [java]     at
>      [java]     at
>      [java]
> at
> I downloaded the source and line 425 in Javac doesn't make any sense.
> So I guess my next step is to be able to recompile ant and then add
> some logging so I can see what is happening.
> However, I'm sure that I'm not doing anything really difficult...I'm
> just doing it wrong ;-).  A "compile Hello World"-type example would
> save me BUNCHES of work and would be MUCH appreciated.
> Thanks.
> --
> To unsubscribe, e-mail:   <>
> For additional commands, e-mail: <>

                                   -- \m/ --
  "...if I seem super human I have been misunderstood." (c) Dream Theater
 - ICQ: 1934853 JID:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message