You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Bickford, Mark" <Ma...@WrightExpress.com> on 2010/07/27 20:57:58 UTC

SCRIPTDEF using Java

Hi,

I've tried everything I can think of to get this to work, but so far
everything has failed.  I am writing a scriptdef using Java as the
language, but I can't find how to access any of the predefined beans
like attributes and elements.  This much works:

<project name="javaScriptingTest" default="script.test">

   <scriptdef name="javatest" manager="javax" language="java">
      <attribute name="teststring"/>
      <![CDATA[
      import org.apache.tools.ant.taskdefs.optional.*;
      class javatest
      {
      	public static void main(String[] args) {
      		System.out.println("Number of args: "+args.length);
      		//System.out.println(attributes.toString());
      		//System.out.println(elements.toString());
      		//System.out.println("The list is: "+
attributes.get("teststring").toString());
      		System.out.println("Hello world!");
      		}
      	}
      	]]>
   </scriptdef>
   
   <target name="script.test">
      <javatest teststring="Success!!!  Can you believe it???"/>
   </target>
</project>

The command-line I am using (on WinXP) is 
> ant -lib C:\work\lib\java-script-engine\ -f mini-build.xml

(java-script-engine holds the java-engine.jar from the JSR 223 home page
at java.sun.com). 

When I run it as I have things above, it works.  When I uncomment any of
the printlns shown, I get (e.g.):

script.test:
 [javatest] mfm:///$unnamed.java:9: cannot find symbol
 [javatest] symbol  : variable attributes
 [javatest] location: class javatest

I realize that println of attributes wouldn't give anything really
meaningful, but it would prove the object exists.  How can we access
those beans when Java is the script language?  Am I missing an import,
or is there something else that needs to happen?


Thanks, 
Mark H. Bickford 



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