• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ANT file

 
bhaveshkumar chaudhari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing automation of testing. I have a build.xml(ant file) which in turn compiles the code. But the problem is how to execute the command so that file code will get compiled automatically.
 
aleem khan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
command to execute:

ant -f build.xml compile

where compile is the target name in your ant file
 
bhaveshkumar chaudhari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aleem,

Thanks for the reply. I'm still confused. In the command given by you "ant -f build.xml compile" compile is the target name in your ant file. I have build.xml at some location. If we do it manually we give the path of the build file in command prompt and type 'ant' and run the build.xml the same thing I want to do with java program. I mean to say my program won't depend upon the content of the build file.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<project name="MyProject" default="dist" basedir=".">

for default attribute give the target compile or whatever you want to run as default target.
 
Manish Doomra
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by bhaveshkumar chaudhari:
I'm doing automation of testing. I have a build.xml(ant file) which in turn compiles the code. But the problem is how to execute the command so that file code will get compiled automatically.


According, to my understanding, what you want to do is:-
1) Want to Compile your java classes(source code)
2) Confused about what target to call for compilation of your code

Now, as you say that you already have build file named- build.xml, In your build file look for project tag which will be written as


In the above piece of code, in project tag, default target name is mentioned, so it will be called by default if you do not mention any target name with ant command.

if the build file name is build.xml, then no need to mention the build file name, so your command to execute the default target would be 'ant'.

And in default target above, the javac task is called, which does the compilation thing.

For more about ant visit here:- Ant Manual

Let me know, if your query got solved...
 
bhaveshkumar chaudhari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for showing interest. Finally I got the solution from my lead. I created one batch file named "compile.bat" which looks like this,

@echo off

cd %1%

ant

Then I executed the command "Process process = Runtime.getRuntime().exec(sb.toString());" where sb is the string buffer which holds the path of the compile.bat and build.xml.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic