ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Calling Ant from Java: An example please ?
Date Wed, 13 Feb 2002 20:12:26 GMT
Hi Jay,

Well, instead of programmatically generate Java source code, maybe you
should programmatically generate Jython code. The latter can be
automatically compiled to bytecode by the Jython compiler/interpreter, and a
Jython class can extend a Java class (and vice versa if you can believe
me!!!). Most likely, if as you say you want to execute the compiled code you
just generated, the code/class you generate must extend or implement
something (base class / interface) that you know how to deal with.

Another options would be to construct the class you want dynamically,
directly in bytecode. This can be achieved using the newly accepted Jakarta
project BCEL (Byte Code Engineering Library).

I hope this helps. --DD

 -----Original Message-----
From: 	Jay Riddell [mailto:jay@theriddells.org] 
Sent:	Wednesday, February 13, 2002 1:58 PM
To:	Ant Users List; Kevin Toomey
Subject:	Re: Calling Ant from Java: An example please ?

Yes, I am TRYING to do that.
But I am failing miserably.
There are NO EXAMPLES on how to do this; there is only Javadoc
on the API itself (with very little extra explanatory text).

OK, maybe I am not being specific enough here.

Here is the java code that I have written that attempts
to compile a "Hello, world" java file:
http://home.attbi.com/~theriddells/CompileIt.java

And here are the results that I get:
http://home.attbi.com/~theriddells/results.txt

(Sorry for the links, I felt they were too long to be
directly quoted here.)

Thoughts ?  Help ?

Thanks

On 2/13/02 11:15 AM, "Kevin Toomey" <toomeykh@yahoo.com> wrote:

> It sounds like you want to take a look at the org.apache.tools.ant
> package in the API. Using the Project, Target, and Task classes, you
> could implement Diane's example via a Java program.
> 
> --- Jay Riddell <jay@theriddells.org> wrote:
>> Thanks for the quick response  . . . but no ;-)
>> 
>> I want to accomplish this in Java by calling the Ant API.
>> 
>> I need to dynamically:
>>   - generate source code
>>   - compile what was generated
>>   - classload it
>>   - execute it
>> 
>> And I need to do all this as part of a larger application.
>> 
>> How's THAT for fun ?
>> 
>> On 2/13/02 10:47 AM, "Diane Holt" <holtdl@yahoo.com> wrote:
>> 
>>> --- 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.
>>> [snip]
>>>> 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.
>>> 
>>> If I understand right what you want to do (but given the past two
>> days,
>>> that's anybody's guess :), here's an example:
>>> 
>>> <target name="runHello" depends="gensrc,compile">
>>>   <java classname="HelloWorld" >
>>>     <classpath>
>>>       <pathelement location="."/>
>>>     </classpath>
>>>   </java>
>>> </target>
>>> 
>>> <target name="compile">
>>>   <javac srcdir="." destdir="." includes="HelloWorld.java"/>
>>> </target>
>>> 
>>> <target name="gensrc">
>>>   <echo file="HelloWorld.java">public class HelloWorld
>>> {
>>> public static void main (String [] args)
>>> {
>>>     System.out.println("Hello, world") ;
>>> }
>>> }
>>>   </echo>
>>> </target>
>>> 
>>> Diane
>>> 
>>> =====
>>> (holtdl@yahoo.com)
>>> 
>>> 
>>> 
>>> __________________________________________________
>>> Do You Yahoo!?
>>> Send FREE Valentine eCards with Yahoo! Greetings!
>>> http://greetings.yahoo.com
>>> 
>>> --
>>> To unsubscribe, e-mail:
>> <mailto:ant-user-unsubscribe@jakarta.apache.org>
>>> For additional commands, e-mail:
>> <mailto:ant-user-help@jakarta.apache.org>
>>> 
>> 
>> 
>> --
>> To unsubscribe, e-mail:
>> <mailto:ant-user-unsubscribe@jakarta.apache.org>
>> For additional commands, e-mail:
>> <mailto:ant-user-help@jakarta.apache.org>
>> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Send FREE Valentine eCards with Yahoo! Greetings!
> http://greetings.yahoo.com
> 
> --
> To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>
> 


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

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