You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Nadun Herath <ma...@yahoo.com> on 2009/08/27 04:50:33 UTC
Help needed regarding Java task
I am new to apache Ant.
Some part of my build.xml is like this.
<java fork="true" classname="MiniJavaParser" output="result.txt" append="true">
<classpath>
<path location="."/>
</classpath>
<arg file="ArrayLengthTest.java"/>
</java>
<!-- 2 -->
<java fork="true" classname="MiniJavaParser">
<classpath>
<path location="."/>
</classpath>
<arg file="ArrayRefTest.java"/>
</java>
I have to run a Java program Called MiniJavaParser using different file names as arguements several
times using Java Task. When it runs it gives the message
"MiniJava program parsed successfully" or Encountered errors during parse.
I want to declare a variable as a counter and increment it's value when it gives the message "MiniJava Program parsed successfully".
What is the approach I should take.
Thank you very much.
Re: Help needed regarding Java task
Posted by Gilbert Rebhan <an...@schillbaer.de>.
Nadun Herath schrieb:
...
> I have to run a Java program Called MiniJavaParser using different file names as arguements several
> times using Java Task. When it runs it gives the message
>
> "MiniJava program parsed successfully" or Encountered errors during parse.
>
> I want to declare a variable as a counter and increment it's value when it gives the message "MiniJava Program parsed successfully".
>
> What is the approach I should take.
...
when your java task does things "several times" why not make it a new
ant task or a macrodef / scriptdef (use a language that runs on JVM via
BSF, f.e. jruby/groovy/beanshell/javascript/jython ...) ?
That way you'll have full access to ant api and project scope, means you
may set new properties (and even overwrite existing properties f.e. a
counter) for further processing in your ant workflow.
Other approaches =
grep the return from your java class with outputproperty, find examples
via google > ant+java+outputproperty, first result gives me =
http://www.nabble.com/%3Cjava%3E-outputproperty-problem--td19528043.html
the java task has several attributes to catch stdout stderr .. see =
http://ant.apache.org/manual/CoreTasks/java.html
low level = writing to a file as already mentioned in another post
from this thread
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Help needed regarding Java task
Posted by Nadun Herath <ma...@yahoo.com>.
Hi Aviesh
Thanks a lot for the reply again. What I mean was sometime my programe output the message
"MiniJava program parsed successfully."
Sometime it output the message " Encountered errors during parse."
How can declare a variable to count the number of times MiniJava program parsed succesfully.
Mind you there are number of Java tasks define in the build file.
www.nadunh.blogspot.com
________________________________
From: Avlesh Singh <av...@gmail.com>
To: Ant Users List <us...@ant.apache.org>
Sent: Thursday, August 27, 2009 9:46:54 AM
Subject: Re: Help needed regarding Java task
As such, the JAVA programme cannot "return" something. You can always write
the counter value in a file. Both your java program and ant can read from
the same file.
Cheers
Avlesh
On Thu, Aug 27, 2009 at 9:42 AM, Nadun Herath <ma...@yahoo.com>wrote:
> Hi Aviesh
>
> Thanks a lot for the reply. I want a declare variable and increment it's
> value according the output of the java programe.
> Is there a way to achieve that. Will I have to include a script in the
> build file to achive that.
>
> www.nadunh.blogspot.com
>
>
>
>
> ________________________________
> From: Avlesh Singh <av...@gmail.com>
> To: Ant Users List <us...@ant.apache.org>
> Sent: Thursday, August 27, 2009 9:25:21 AM
> Subject: Re: Help needed regarding Java task
>
> See, if this usage helps:
>
> <target name="search">
> <java classname="com.me.searcher.DefaultSearcher" fork="true">
> <arg value="${keyword}"/>
> <classpath refid="classpath" />
> </java>
> </target>
>
> <path id="classpath">
> <fileset dir="${build.dir}" includes="*.jar" />
> <fileset dir="${lib.dir}" includes="*.jar" />
> <fileset dir="${conf.dir}" includes="*.properties" />
> <pathelement path="${build.dir}" />
> </path>
>
> This is being used in the following manner - "ant search -Dkeyword=obama
>
> Cheers
> Avlesh
>
> On Thu, Aug 27, 2009 at 8:20 AM, Nadun Herath <malakaherath@yahoo.com
> >wrote:
>
> > I am new to apache Ant.
> >
> > Some part of my build.xml is like this.
> >
> > <java fork="true" classname="MiniJavaParser" output="result.txt"
> > append="true">
> > <classpath>
> > <path location="."/>
> > </classpath>
> > <arg file="ArrayLengthTest.java"/>
> > </java>
> >
> > <!-- 2 -->
> > <java fork="true" classname="MiniJavaParser">
> > <classpath>
> > <path location="."/>
> > </classpath>
> > <arg file="ArrayRefTest.java"/>
> > </java>
> >
> > I have to run a Java program Called MiniJavaParser using different
> file
> > names as arguements several
> > times using Java Task. When it runs it gives the message
> >
> > "MiniJava program parsed successfully" or Encountered errors during
> > parse.
> >
> > I want to declare a variable as a counter and increment it's value when
> it
> > gives the message "MiniJava Program parsed successfully".
> >
> > What is the approach I should take.
> >
> > Thank you very much.
> >
> >
> >
>
>
>
>
Re: Help needed regarding Java task
Posted by Avlesh Singh <av...@gmail.com>.
As such, the JAVA programme cannot "return" something. You can always write
the counter value in a file. Both your java program and ant can read from
the same file.
Cheers
Avlesh
On Thu, Aug 27, 2009 at 9:42 AM, Nadun Herath <ma...@yahoo.com>wrote:
> Hi Aviesh
>
> Thanks a lot for the reply. I want a declare variable and increment it's
> value according the output of the java programe.
> Is there a way to achieve that. Will I have to include a script in the
> build file to achive that.
>
> www.nadunh.blogspot.com
>
>
>
>
> ________________________________
> From: Avlesh Singh <av...@gmail.com>
> To: Ant Users List <us...@ant.apache.org>
> Sent: Thursday, August 27, 2009 9:25:21 AM
> Subject: Re: Help needed regarding Java task
>
> See, if this usage helps:
>
> <target name="search">
> <java classname="com.me.searcher.DefaultSearcher" fork="true">
> <arg value="${keyword}"/>
> <classpath refid="classpath" />
> </java>
> </target>
>
> <path id="classpath">
> <fileset dir="${build.dir}" includes="*.jar" />
> <fileset dir="${lib.dir}" includes="*.jar" />
> <fileset dir="${conf.dir}" includes="*.properties" />
> <pathelement path="${build.dir}" />
> </path>
>
> This is being used in the following manner - "ant search -Dkeyword=obama
>
> Cheers
> Avlesh
>
> On Thu, Aug 27, 2009 at 8:20 AM, Nadun Herath <malakaherath@yahoo.com
> >wrote:
>
> > I am new to apache Ant.
> >
> > Some part of my build.xml is like this.
> >
> > <java fork="true" classname="MiniJavaParser" output="result.txt"
> > append="true">
> > <classpath>
> > <path location="."/>
> > </classpath>
> > <arg file="ArrayLengthTest.java"/>
> > </java>
> >
> > <!-- 2 -->
> > <java fork="true" classname="MiniJavaParser">
> > <classpath>
> > <path location="."/>
> > </classpath>
> > <arg file="ArrayRefTest.java"/>
> > </java>
> >
> > I have to run a Java program Called MiniJavaParser using different
> file
> > names as arguements several
> > times using Java Task. When it runs it gives the message
> >
> > "MiniJava program parsed successfully" or Encountered errors during
> > parse.
> >
> > I want to declare a variable as a counter and increment it's value when
> it
> > gives the message "MiniJava Program parsed successfully".
> >
> > What is the approach I should take.
> >
> > Thank you very much.
> >
> >
> >
>
>
>
>
Re: Help needed regarding Java task
Posted by Nadun Herath <ma...@yahoo.com>.
Hi Aviesh
Thanks a lot for the reply. I want a declare variable and increment it's value according the output of the java programe.
Is there a way to achieve that. Will I have to include a script in the build file to achive that.
www.nadunh.blogspot.com
________________________________
From: Avlesh Singh <av...@gmail.com>
To: Ant Users List <us...@ant.apache.org>
Sent: Thursday, August 27, 2009 9:25:21 AM
Subject: Re: Help needed regarding Java task
See, if this usage helps:
<target name="search">
<java classname="com.me.searcher.DefaultSearcher" fork="true">
<arg value="${keyword}"/>
<classpath refid="classpath" />
</java>
</target>
<path id="classpath">
<fileset dir="${build.dir}" includes="*.jar" />
<fileset dir="${lib.dir}" includes="*.jar" />
<fileset dir="${conf.dir}" includes="*.properties" />
<pathelement path="${build.dir}" />
</path>
This is being used in the following manner - "ant search -Dkeyword=obama
Cheers
Avlesh
On Thu, Aug 27, 2009 at 8:20 AM, Nadun Herath <ma...@yahoo.com>wrote:
> I am new to apache Ant.
>
> Some part of my build.xml is like this.
>
> <java fork="true" classname="MiniJavaParser" output="result.txt"
> append="true">
> <classpath>
> <path location="."/>
> </classpath>
> <arg file="ArrayLengthTest.java"/>
> </java>
>
> <!-- 2 -->
> <java fork="true" classname="MiniJavaParser">
> <classpath>
> <path location="."/>
> </classpath>
> <arg file="ArrayRefTest.java"/>
> </java>
>
> I have to run a Java program Called MiniJavaParser using different file
> names as arguements several
> times using Java Task. When it runs it gives the message
>
> "MiniJava program parsed successfully" or Encountered errors during
> parse.
>
> I want to declare a variable as a counter and increment it's value when it
> gives the message "MiniJava Program parsed successfully".
>
> What is the approach I should take.
>
> Thank you very much.
>
>
>
Re: Help needed regarding Java task
Posted by Avlesh Singh <av...@gmail.com>.
See, if this usage helps:
<target name="search">
<java classname="com.me.searcher.DefaultSearcher" fork="true">
<arg value="${keyword}"/>
<classpath refid="classpath" />
</java>
</target>
<path id="classpath">
<fileset dir="${build.dir}" includes="*.jar" />
<fileset dir="${lib.dir}" includes="*.jar" />
<fileset dir="${conf.dir}" includes="*.properties" />
<pathelement path="${build.dir}" />
</path>
This is being used in the following manner - "ant search -Dkeyword=obama
Cheers
Avlesh
On Thu, Aug 27, 2009 at 8:20 AM, Nadun Herath <ma...@yahoo.com>wrote:
> I am new to apache Ant.
>
> Some part of my build.xml is like this.
>
> <java fork="true" classname="MiniJavaParser" output="result.txt"
> append="true">
> <classpath>
> <path location="."/>
> </classpath>
> <arg file="ArrayLengthTest.java"/>
> </java>
>
> <!-- 2 -->
> <java fork="true" classname="MiniJavaParser">
> <classpath>
> <path location="."/>
> </classpath>
> <arg file="ArrayRefTest.java"/>
> </java>
>
> I have to run a Java program Called MiniJavaParser using different file
> names as arguements several
> times using Java Task. When it runs it gives the message
>
> "MiniJava program parsed successfully" or Encountered errors during
> parse.
>
> I want to declare a variable as a counter and increment it's value when it
> gives the message "MiniJava Program parsed successfully".
>
> What is the approach I should take.
>
> Thank you very much.
>
>
>