0

I'm trying to work out how I can run an ant task without actually needed a build.xml. In particular I want to run a JUnit task with a formatter. In xml format this looks like below:

<junit printsummary="true" errorProperty="test.failed" failureProperty="test.failed">
    <classpath refid="run.class.path" />

    <!-- console log -->
    <formatter type="xml" classname="be.x.SFFormatter" />

    <test name="be.x.SF" outfile="result" todir="${build.output.dir}" />
</junit>

It works when running the ant script, but I would like to get my app running as a runnable jar. Running the tests from Java was easy:

    JUnitCore junit = new JUnitCore();
    testResult = junit.run(SeleniumFramework.class);

However, I struggle to work out how to actually get the formatter to work. The formatter is of type org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter so I doubt I can just plug it in somewhere without running ant.

Has anyone done something similar before? Thanks!

2 Answers 2

2

Ant doesn't do any magic. All it does is read the XML file, create the beans specified in it and then execute the methods as per the Task API (org.apache.tools.ant.Task).

So all you need is to do the same in your code. Don't forget to create a Project :-)

1
  • I've decided to just bundle the build file into my jar and run it internally. A bit sad it makes my end product depend on ant now, but for the moment I can live with it Jul 24, 2012 at 8:48
1

You may use Ant via Groovy to avoid the xml syntax.
See => Using Ant from Groovy for details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.