ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: Call a class with params from ANT
Date Thu, 06 May 2004 08:06:31 GMT
What do you mean with "call a class"?

1) You can start a java application with <java>. Arguments can be passed
with nested <arg>s.
But the class has to have the main-method.

class MyClass {
    public static void main(String[] args) {
        for (int i=0; i<args.length; i++) System.out.println(args[i]);
    }
}

<java classname="MyClass">
    <arg value="Hello"/>
    <arg value="World"/>
</java>

[java] Hello
[java] World



2) You can use a class inside your buildfile via <script>. Inside the script
task you write
the defined language and access directly the class.

package mypackage
class MyClass {
    private String a;
    private String b;
    public MyClass(String a, String b) {
        this.a = a;
        this.b = b;
    }
    public void print() {
        System.out.println(a);
        System.out.println(b);
    }
}

<script language="javascript"> <![CDATA[
    importClass(Package.mypackage.MyClass);
    object = new MyClass("Hello", "World");
    object.print();
]]></script>

[script] Hello
[script] World



(not tested)

Jan






> -----Original Message-----
> From: skalsky@oksystem.cz [mailto:skalsky@oksystem.cz]
> Sent: Thursday, May 06, 2004 9:53 AM
> To: user@ant.apache.org
> Subject: Call a class with params from ANT
> 
> 
> Hello,
> 	I'm a beginner with Java and using ANT ... and have a 
> problem how to call a class with params - is it possible with 
> ANT tasks? Or have I  to create my own task? The constructor 
> of the class needs 2 parameters.
> 
> Could somebody tell me where can I find any info about it?
> Thanx for your answers.
> 
> 	Milan
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message