ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Derricutt <m...@talios.com>
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 (www.beanshell.org), 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);
  bsh.eval(code);

}

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

Mark

--On Wednesday, 13 February 2002 10:29 a.m. -0800 Jay Riddell 
<jay@theriddells.org> 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
> org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:425)
>      [java]     at org.apache.tools.ant.Target.execute(Target.java:153)
>      [java]     at
> org.apache.tools.ant.Project.runTarget(Project.java:898)      [java]
> at
> org.apache.tools.ant.Project.executeTarget(Project.java:536)
>
> 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:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>
>



                                   -- \m/ --
  "...if I seem super human I have been misunderstood." (c) Dream Theater
          mark@talios.com - ICQ: 1934853 JID: talios@myjabber.net

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message