ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shailesh Sharma <shailesh_s...@yahoo.com>
Subject Problem in Calling Ant from a Java main; Please Help !
Date Wed, 03 Mar 2004 16:09:18 GMT
Hi,
can somebody please help me with this problem:
 
1) I have created a simple scsmail.xml build file like this: This file just echo message.
 
<?xml version="1.0" encoding="iso-8859-1"?>
<project name="dev" default="all" basedir=".">
<!-- This is configurations for deploying an application on wls8.1 on win2000 machine -->
    <target name="all">
    
     <echo message="...........This is the TESTNET box........."/>
        
    </target>
</project>
 
2) I have created 2 java files like this:
 
import org.apache.tools.ant.taskdefs.Ant;
import org.apache.tools.ant.taskdefs.Property;
import org.apache.tools.ant.types.*;
import org.apache.tools.ant.*;
import org.apache.tools.ant.taskdefs.ExecTask;
import org.apache.tools.ant.types.Commandline;
import java.io.File;
/**
 * Creates an Ant project to run an Ant build
 * @author Sangita
 * @version 1.0
 */
public class RunTest extends Ant {

  public RunTest() {
    project = new Project();
    project.init();
    //setOutput("C:/test/outputFile.txt");
    System.out.println("printing 1 ....");

    ExecTask exec = new ExecTask();
    exec.setProject(project);
    exec.setExecutable("C:/bea/weblogic81/server/bin/ant.bat");
 exec.setDir(new java.io.File("C:/test"));
 Commandline.Argument arg = exec.createArg();
 arg.setLine("-buildfile -f C:/test/scsmail.xml -listener org.apache.tools.ant.XmlLogger -logfile
./log.xml");
 System.out.println("printing 2....");
    exec.execute();
    System.out.println("printing 3....");
  }
}
 
---------------------------------second java file that invokes the above file----
 
import org.apache.tools.ant.*;
import org.apache.tools.ant.BuildException;
//import RunTest;
public class RunSomeTest {
  public static void main(String[] args) {

    try{
  RunTest rt = new RunTest();
  //rt.execute();
    } catch(BuildException be) {
      be.printStackTrace();
    }
  }
}

3) I have these 2 files succesfully.
 
4) Now when iam running the RunSomeTest file as:

C:\test>java RunSomeTest
printing 1 ....
printing 2....
printing 3....
 
i.e the class runs OK .....but the problem is there is nothing written to the log file.
 
5) WHEREAS when iam running this command directly from the command line, it writes lot of
information into the log file.
 
C:\test>ant -f scsmail.xml all -listener org.apache.tools.ant.XmlLogger -logfile ./log.xml
 
 
 
could somebody please help me understanding the problem related on step#4.
 
-shailesh

"Alexey N. Solofnenko" <A.Solofnenko@mdl.com> wrote:
I am using Jython scripts, since it runs in JVM and it does not require 
anything additional on the build computer (Java is a prerequisite 
anyway). Perl is also convenient.

- Alexey.

Shailesh Sharma wrote:

>hmmm, cool. atleast it gives me some insight. iam curious, what package
>are you guys using to parse the ANT output ???
> 
> 
>
>
>"Alexey N. Solofnenko" wrote:
>It is a custom tool that parses ANT output and creates several reports 
>about what components were built, how much time each step took, what 
>target failed, and so on. Even if its sources were useful I doubt my 
>company would allow it.
>
>- Alexey.
>
>Shailesh Sharma wrote:
>
> 
>
>>Alex,
>>could you please explain more on your "build log analyzer that produces
>>an HTML report about the build"
>>
>>and if you can share your build log analyzer code with us ?
>>
>>
>>-shailesh
>>
>>
>>"Alexey N. Solofnenko" wrote:
>>I would put every into a separate target, specify dependency 
>>between them, if any and run them with "-k" option. For my builds I 
>>wrote a build log analyzer that produces an HTML report about the
>> 
>>
>build.
> 
>
>>- Alexey.
>>
>>DDU DUQUENNOY Didier wrote:
>>
>>
>>
>> 
>>
>>>Hi,
>>>
>>>I'm (still) trying to automate the run of the junit tests of all my
>>>
>>>
>>> 
>>>
>>modules, running Ant 1.6.0 on a Windows 2000 machine.
>>
>>
>> 
>>
>>>Each module has a build.xml script with a 'test' task defined. The
>>> 
>>>
>test
> 
>
>>> 
>>>
>>task first compile the classes and then run a junit task which outputs
>> 
>>
>a
> 
>
>>XML file.
>>
>>
>> 
>>
>>>I want to be able to invoke all these tasks and then build a report
>>>
>>>
>>> 
>>>
>>using .
>>
>>
>> 
>>
>>>The problem I'm facing are:
>>>- if a module doesn't compile, I want the next module to be tested. 
>>>- if a module doesn't compile I'd like to be able to see it in the
>>>
>>>
>>> 
>>>
>>final report
>>
>>
>> 
>>
>>>I first thought of a main script like this :
>>>
>>>
>>>
>>>
>>>[...]
>>>
>>>
>>>but it isn't OK because the run will stop if a module doesn't compile.
>>>
>>>So I though of writing a main java class to call my ant scripts. I
>>>
>>>
>>> 
>>>
>>should then be able to detect the failure of a test a do what I want
>>then.
>>
>>
>> 
>>
>>>Here are the techniques I tried:
>>>
>>>- use java.lang.Runtime.exec() : I go asynchronous and I can't check
>>>
>>>
>>> 
>>>
>>the state of the run
>>
>>
>> 
>>
>>>- use org.apache.tools.ant.launch.Launcher : the first script runs,
>>> 
>>>
>but
> 
>
>>> 
>>>
>>it seems that there is a System.exit() after :-(
>>
>>
>> 
>>
>>>- use or a ProjectHelper to build the project :
>>>ProjectHelper.getProjectHelper();
>>>Project project = new Project();
>>>helper.parse(project, xmlFile);
>>>Target target = (Target)targetTable.get("test");
>>>target.execute();
>>>
>>>but I get an error "Could not create task or type of type: junit". But
>>>
>>>
>>> 
>>>
>>junit.jar and all the contents of Ant1.6/lib is in my classpath
>>
>>
>> 
>>
>>>- use of org.apache.tools.ant.taskdefs.Ant to simulate a :
>>>Ant antTask = new Ant();
>>>antTask.setProject(new Project());
>>>antTask.setAntfile(xmlFile);
>>>antTask.setTarget("test");
>>>antTask.execute();
>>>
>>>but I get an error "Could not create task or type of type: property".
>>>
>>>
>>> 
>>>
>>(???)
>>
>>
>> 
>>
>>>Well, how can I do the trick?
>>>
>>>Didier D
>>>
>>>______________________________________________________________________
>>> 
>>>
>_
> 
>
>>> 
>>>
>>__________________________________
>>
>>
>> 
>>
>>>Ce message (et toutes les pièces jointes) sont confidentiels ; son
>>>
>>>
>>> 
>>>
>>contenu ne représente en aucun cas un engagement de la part de DEXIA
>>SOFAXIS. Toute publication, utilisation ou diffusion, même partielle,
>>doit être autorisée préalablement par l'émetteur. 
>>
>>
>> 
>>
>>>Si vous n'êtes pas destinataire de ce message, merci d'en avertir
>>>
>>>
>>> 
>>>
>>immédiatement l'expéditeur.
>>
>>
>> 
>>
>>>Conformément aux dispositions de la loi n° 78-17 du 6 janvier 1978
>>>
>>>
>>> 
>>>
>>relative à l'informatique, aux fichiers et aux libertés, vous pouvez
>>obtenir communication et, le cas échéant, rectification ou suppression
>>des informations vous concernant en vous adressant à DEXIA SOFAXIS -
>>Route de Creton - 18110 VASSELAY
>>
>>
>> 
>>
>>>______________________________________________________________________
>>> 
>>>
>_
> 
>
>>> 
>>>
>>__________________________________
>>
>>
>> 
>>
>>>Consultez notre site internet http://www.sofaxis.com
>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>>For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>>
>>>
>>> 
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>---------------------------------
>>Do you Yahoo!?
>>Yahoo! Search - Find what you’re looking for faster.
>>
>>
>>
>>
>> 
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>---------------------------------
>Do you Yahoo!?
>Yahoo! Search - Find what you’re looking for faster.
>
>
> 
>

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


---------------------------------
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message